Skip to main content

Guidance for Retail Analytics using Generative AI on AWS

Overview

This Guidance shows how to use large language models (LLMs) to generate SQL queries and perform data analytics, enhancing the value of your data. It leverages Amazon Bedrock and Amazon SageMaker to build a SQL generator that uses natural language processing (NLP). To improve accuracy for SQL generation, this Guidance also uses retrieval augmented generation (RAG) to retrieve historical data as few-shot samples in the prompt. With this Guidance, you can optimize costs for data analysis and operations teams by automating routine tasks, reducing working hours, and minimizing labor costs.

How it works

These technical details feature an architecture diagram to illustrate how to effectively use this solution. The architecture diagram shows the key components and their interactions, providing an overview of the architecture's structure and functionality step-by-step.

Deploy with confidence

Ready to deploy? Review the sample code on GitHub for detailed deployment instructions to deploy as-is or customize to fit your needs. 

Go to sample code

Well-Architected Pillars

The architecture diagram above is an example of a Solution created with Well-Architected best practices in mind. To be fully Well-Architected, you should follow as many Well-Architected best practices as possible.

AWS managed services like Amazon ECS, Amazon Bedrock, and SageMaker offload operational burden, allowing developers to focus on application logic rather than undifferentiated heavy lifting tasks. These services handle provisioning, scaling, patching, and infrastructure maintenance, so applications can handle varying user traffic without compromising performance or availability through automatic scaling capabilities.

Read the Operational Excellence whitepaper 

AWS Identity and Access Management (IAM) manages access to AWS resources by creating and managing users and groups, controlling their permissions to perform specific actions on specific resources. Implementing the principle of least privilege minimizes the risk of unauthorized access, enhancing application security.

Read the Security whitepaper 

Amazon ECS relieves the responsibility of managing and scaling underlying infrastructure, reducing operational overhead and enabling automatic scaling and recovery from failures. OpenSearch Service provides high availability and resilience against node failures or data loss, helping ensure critical functionalities remain uninterrupted.

Read the Reliability whitepaper 

OpenSearch Service is a distributed search and analytics engine leveraging Apache Lucene for high-performance text search and data retrieval. It enables efficient storage and fast retrieval of large volumes of data, such as our historical question and SQL datasets. By using OpenSearch Service in this Guidance, you can rapidly access relevant information and assemble prompts for our text-to-SQL functionality, benefiting from its caching mechanisms and distributed architecture for enhanced performance.

Read the Performance Efficiency whitepaper 

OpenSearch Service is a managed service that relieves you from managing search infrastructure. AWS handles the underlying resources, patching, and scaling, allowing you to focus on application functionality. Its ability to scale resources based on usage help optimize costs by avoiding overprovisioning or under-utilization of resources.

Read the Cost Optimization whitepaper 

AWS Cloud infrastructure is designed for sustainability, leveraging energy-efficient data centers, renewable energy sources, and optimized resource utilization. You can offload infrastructure management to AWS, reducing environmental impact while leveraging sustainable practices for search and analytics needs.

Read the Sustainability whitepaper 

Disclaimer

The sample code; software libraries; command line tools; proofs of concept; templates; or other related technology (including any of the foregoing that are provided by our personnel) is provided to you as AWS Content under the AWS Customer Agreement, or the relevant written agreement between you and AWS (whichever applies). You should not use this AWS Content in your production accounts, or on production or other critical data. You are responsible for testing, securing, and optimizing the AWS Content, such as sample code, as appropriate for production grade use based on your specific quality control practices and standards. Deploying AWS Content may incur AWS charges for creating or using AWS chargeable resources, such as running Amazon EC2 instances or using Amazon S3 storage.