Traditionally, financial data analysis could require deep SQL expertise and database knowledge. Now with Amazon Bedrock Knowledge Bases integration with structured data, you can use simple, natural language prompts to query complex financial datasets. By combining the AI capabilities of Amazon Bedrock with an Amazon Redshift data warehouse, individuals with varied levels of technical expertise can quickly generate valuable insights, making sure that data-driven decision-making is no longer limited to those with specialized programming skills.
With the support for structured data retrieval using Amazon Bedrock Knowledge Bases, you can now use natural language querying to retrieve structured data from your data sources, such as Amazon Redshift. This enables applications to seamlessly integrate natural language processing capabilities on structured data through simple API calls. Developers can rapidly implement sophisticated data querying features without complex coding—just connect to the API endpoints and let users explore financial data using plain English. From customer portals to internal dashboards and mobile apps, this API-driven approach makes enterprise-grade data analysis accessible to everyone in your organization. Using structured data from a Redshift data warehouse, you can efficiently and quickly build generative AI applications for tasks such as text generation, sentiment analysis, or data translation.
In this post, we showcase how financial planners, advisors, or bankers can now ask questions in natural language, such as, “Give me the name of the customer with the highest number of accounts?” or “Give me details of all accounts for a specific customer.” These prompts will receive precise data from the customer databases for accounts, investments, loans, and transactions. Amazon Bedrock Knowledge Bases automatically translates these natural language queries into optimized SQL statements, thereby accelerating time to insight, enabling faster discoveries and efficient decision-making.
Solution overview
To illustrate the new Amazon Bedrock Knowledge Bases integration with structured data in Amazon Redshift, we will build a conversational AI-powered assistant for financial assistance that is designed to help answer financial inquiries, like “Who has the most accounts?” or “Give details of the customer with the highest loan amount.”
We will build a solution using sample financial datasets and set up Amazon Redshift as the knowledge base. Users and applications will be able to access this information using natural language prompts.
The following diagram provides an overview of the solution.
For building and running this solution, the steps include:
- Load sample financial datasets.
- Enable Amazon Bedrock large language model (LLM) access for Amazon Nova Pro.
- Create an Amazon Bedrock knowledge base referencing structured data in Amazon Redshift.
- Ask queries and get responses in natural language.
To implement the solution, we use a sample financial dataset that is for demonstration purposes only. The same implementation approach can be adapted to your specific datasets and use cases.
Download the SQL script to run the implementation steps in Amazon Redshift Query Editor V2. If you’re using another SQL editor, you can copy and paste the SQL queries either from this post or from the downloaded notebook.
Prerequisites
Make sure your meet the following prerequisites:
- Have an AWS account.
- Create an Amazon Redshift Serverless workgroup or provisioned cluster. For setup instructions, see Creating a workgroup with a namespace or Create a sample Amazon Redshift database, respectively. The Amazon Bedrock integration feature is supported in both Amazon Redshift provisioned and serverless.
- Create an AWS Identity and Access Management (IAM) role. For instructions, see Creating or updating an IAM role for Amazon Redshift ML integration with Amazon Bedrock.
- Associate the IAM role to a Redshift instance.
- Set up the required permissions for Amazon Bedrock Knowledge Bases to connect with Amazon Redshift.
Load sample financial data
To load the finance datasets to Amazon Redshift, complete the following steps:
- Open the Amazon Redshift Query Editor V2 or another SQL editor of your choice and connect to the Redshift database.
- Run the following SQL to create the finance data tables and load sample data:
- Download the sample financial dataset to your local storage and unzip the zipped folder.
- Create an Amazon Simple Storage Service (Amazon S3) bucket with a unique name. For instructions, refer to Creating a general purpose bucket.
- Upload the downloaded files into your newly created S3 bucket.
- Using the following COPY command statements, load the datasets from Amazon S3 into the new tables you created in Amazon Redshift. Replace
<
with the name of your S3 bucket and> <
with your AWS Region.>
Enable LLM access
With Amazon Bedrock, you can access state-of-the-art AI models from providers like Anthropic, AI21 Labs, Stability AI, and Amazon’s own foundation models (FMs). These include Anthropic’s Claude 2, which excels at complex reasoning and content generation; Jurassic-2 from AI21 Labs, known for its multilingual capabilities; Stable Diffusion from Stability AI for image generation; and Amazon Titan models for various text and embedding tasks. For this demo, we use Amazon Bedrock to access the Amazon Nova FMs. Specifically, we use the Amazon Nova Pro model, which is a highly capable multimodal model designed for a wide range of tasks like video summarization, Q&A, mathematical reasoning, software development, and AI agents, including high speed and accuracy for text summarization tasks.
Make sure you have the required IAM permissions to enable access to available Amazon Bedrock Nova FMs. Then complete the following steps to enable model access in Amazon Bedrock:
- On the Amazon Bedrock console, in the navigation pane, choose Model access.
- Choose Enable specific models.
- Search for Amazon Nova models, select Nova Pro, and choose Next.
- Review the selection and choose Submit.
Create an Amazon Bedrock knowledge base referencing structured data in Amazon Redshift
Amazon Bedrock Knowledge Bases uses Amazon Redshift as the query engine to query your data. It reads metadata from your structured data store to generate SQL queries. There are different supported authentication methods to create the Amazon Bedrock knowledge base using Amazon Redshift. For more information, refer to the Set up query engine for your structured data store in Amazon Bedrock Knowledge Bases.
For this post, we create an Amazon Bedrock knowledge base for the Redshift database and sync the data using IAM authentication.
If you’re creating an Amazon Bedrock knowledge base through the AWS Management Console, you can skip the service role setup mentioned in the previous section. It automatically creates one with the necessary permissions for Amazon Bedrock Knowledge Bases to retrieve data from your new knowledge base and generate SQL queries for structured data stores.
When creating an Amazon Bedrock knowledge base using an API, you must attach IAM policies that grant permissions to create and manage knowledge bases with connected data stores. Refer to Prerequisites for creating an Amazon Bedrock Knowledge Base with a structured data store for instructions.
Complete the following steps to create an Amazon Bedrock knowledge base using structured data:
- On the Amazon Bedrock console, choose Knowledge Bases in the navigation pane.
- Choose Create and choose Knowledge Base with structure data store from the dropdown menu.
- Provide the following details for your knowledge base:
- Enter a name and optional description.
- Select Amazon Redshift as the query engine.
- Select Create and use a new service role for resource management.
- Make note of this newly created IAM role.
- Choose Next to proceed to the next part of the setup process.
- Configure the query engine:
- Select Redshift Serverless (Amazon Redshift provisioned is also supported).
- Choose your Redshift workgroup.
- Use the IAM role created earlier.
- Under Default storage metadata, select Amazon Redshift databases and for Database, choose dev.
- You can customize settings by adding specific contexts to enhance the accuracy of the results.
- Choose Next.
- Complete creating your knowledge base.
- Record the generated service role details.
- Next, grant appropriate access to the service role for Amazon Bedrock Knowledge Bases through the Amazon Redshift Query Editor V2. Update
in the following statements with your service role, and update the value for .
Now you can update the knowledge base with the Redshift database.
- On the Amazon Bedrock console, choose Knowledge Bases in the navigation pane.
- Open the knowledge base you created.
- Select the dev Redshift database and choose Sync.
It may take a few minutes for the status to display as COMPLETE.
Ask queries and get responses in natural language
You can set up your application to query the knowledge base or attach the knowledge base to an agent by deploying your knowledge base for your AI application. For this demo, we use a native testing interface on the Amazon Bedrock Knowledge Bases console.
To ask questions in natural language on the knowledge base for Redshift data, complete the following steps:
- On the Amazon Bedrock console, open the details page for your knowledge base.
- Choose Test.
- Choose your category (Amazon), model (Nova Pro), and inference settings (On demand), and choose Apply.
- In the right pane of the console, test the knowledge base setup with Amazon Redshift by asking a few simple questions in natural language, such as “How many tables do I have in the database?” or “Give me list of all tables in the database.”
The following screenshot shows our results.
- To view the generated query from your Amazon Redshift based knowledge base, choose Show details next to the response.
- Next, ask questions related to the financial datasets loaded in Amazon Redshift using natural language prompts, such as, “Give me the name of the customer with the highest number of accounts” or “Give the details of all accounts for customer Deanna McCoy.”
The following screenshot shows the responses in natural language.
Using natural language queries in Amazon Bedrock, you were able to retrieve responses from the structured financial data stored in Amazon Redshift.
Considerations
In this section, we discuss some important considerations when using this solution.
Security and compliance
When integrating Amazon Bedrock with Amazon Redshift, implementing robust security measures is crucial. To protect your systems and data, implement essential safeguards including restricted database roles, read-only database instances, and proper input validation. These measures help prevent unauthorized access and potential system vulnerabilities. For more information, see Allow your Amazon Bedrock Knowledge Bases service role to access your data store.
Cost
You incur a cost for converting natural language to text based on SQL. To learn more, refer to Amazon Bedrock pricing.
Use custom contexts
To improve query accuracy, you can enhance SQL generation by providing custom context in two key ways. First, specify which tables to include or exclude, focusing the model on relevant data structures. Second, supply curated queries as examples, demonstrating the types of SQL queries you expect. These curated queries serve as valuable reference points, guiding the model to generate more accurate and relevant SQL outputs tailored to your specific needs. For more information, refer to Create a knowledge base by connecting to a structured data store.
For different workgroups, you can create separate knowledge bases for each group, with access only to their specific tables. Control data access by setting up role-based permissions in Amazon Redshift, verifying each role can only view and query authorized tables.
Clean up
To avoid incurring future charges, delete the Redshift Serverless instance or provisioned data warehouse created as part of the prerequisite steps.
Conclusion
Generative AI applications provide significant advantages in structured data management and analysis. The key benefits include:
- Using natural language processing – This makes data warehouses more accessible and user-friendly
- Enhancing customer experience – By providing more intuitive data interactions, it boosts overall customer satisfaction and engagement
- Simplifying data warehouse navigation – Users can understand and explore data warehouse content through natural language interactions, improving ease of use
- Improving operational efficiency – By automating routine tasks, it allows human resources to focus on more complex and strategic activities
In this post, we showed how the natural language querying capabilities of Amazon Bedrock Knowledge Bases when integrated with Amazon Redshift enables rapid solution development. This is particularly valuable for the finance industry, where financial planners, advisors, or bankers face challenges in accessing and analyzing large volumes of financial data in a secured and performant manner.
By enabling natural language interactions, you can bypass the traditional barriers of understanding database structures and SQL queries, and quickly access insights and provide real-time support. This streamlined approach accelerates decision-making and drives innovation by making complex data analysis accessible to non-technical users.
For additional details on Amazon Bedrock and Amazon Redshift integration, refer to Amazon Redshift ML integration with Amazon Bedrock.
About the authors
Nita Shah is an Analytics Specialist Solutions Architect at AWS based out of New York. She has been building data warehouse solutions for over 20 years and specializes in Amazon Redshift. She is focused on helping customers design and build enterprise-scale well-architected analytics and decision support platforms.
Sushmita Barthakur is a Senior Data Solutions Architect at Amazon Web Services (AWS), supporting Strategic customers architect their data workloads on AWS. With a background in data analytics, she has extensive experience helping customers architect and build enterprise data lakes, ETL workloads, data warehouses and data analytics solutions, both on-premises and the cloud. Sushmita is based in Florida and enjoys traveling, reading and playing tennis.
Jonathan Katz is a Principal Product Manager – Technical on the Amazon Redshift team and is based in New York. He is a Core Team member of the open source PostgreSQL project and an active open source contributor, including PostgreSQL and the pgvector project.