AWS for Industries
How bpx energy uses Amazon Bedrock to transform oil and gas production insights
This is a guest post cowritten with Matthew Mcelhaney, Ayush Rastogi, and Chuanyue Shen from bpx energy.
bpx energy (bpx) operates bp’s US onshore portfolio. bpx operates in a highly competitive business environment and projects to grow production volumes 30 percent by 2025, relative to 2022 levels. Technology will enable this production increase and Generative Artificial Intelligence (GenAI) is projected to be a key driver.
Every day, bpx field and office employees spend hours reviewing production and performance data of wells to identify assets that need further attention for optimization. Manually interpreting production data across thousands of wells is labor intensive and not effective for mitigating critical issues in a timely manner, potentially resulting in a loss in production. bpx wanted to build an automated solution that would analyze well production data and align with their long-term vision of using generative AI in achieving operational efficiencies.
bpx worked with the AWS Generative AI Innovation Center and Solutions Architects to build a generative AI–based chat interface for bpx employees, called Xpert. Xpert generates SQL or Python code from a bpx team member’s question, runs the generated code, and provides a text response. It also offers interaction through data retrieval and plot visualization, providing bpx users with a chat-like experience.
Xpert is built on Amazon Bedrock—a fully managed service that offers a choice of high-performing foundation models—and uses bpx data systems. Xpert is intended to be integrated into mobile and voice platforms. Mobile feature integration will allow field personnel to access the insights they need in the future, even from remote locations. Xpert also reduces manual effort—bpx employees spend less time analyzing expansive data assets, instead directly interacting with data using natural language. Xpert demonstrates the potential of GenAI to business and bpx will continue developing GenAI features.
“We’re on the precipice of changing how bpx operates. AI is going to be a core part of bpx’s strategy, and it’s very exciting to be a part of it,” says Matthew McElhaney, bpx’s head of data science and AI. “By implementing Xpert, we estimate that we will save thousands of hours annually.”
This blog post discusses how bpx is using Amazon Bedrock to analyze their assets and enhance employee productivity. The primary source of data for analysis is bpx’s corporate and operational data warehouse, which receives data from a variety of source systems, including data from field systems (operational technology). bpx is revolutionizing the interaction between employees and production data, reducing the time spent on analyzing dashboards.
Generative AI solution overview
Xpert uses Anthropic Claude 3 models in Amazon Bedrock. These models are used through zero-shot and few-shot prompting. Amazon Bedrock provides model choices for bpx team to evaluate based on cost-performance for different use cases. bpx teams design prompt for each component and verify that Xpert is providing the most accurate and helpful responses possible.
Xpert is a generative AI solution that consists of five major components: question rewriter, router, Python generator, SQL generator, and data-to-text generator.
Figure 1. Solution overview of Xpert, using either SQL or Python generation based on user question
After a user submits a question, Xpert rewrites the question, taking into account the conversational context, which includes information provided in previous questions. This rewritten question is sent to a router, which decides whether the question is suitable for Python or SQL generation.
If the router determines that the rewritten question is suitable for Python generation, Xpert will generate the code from the text and run it to generate a plot. This plot can then be used to provide a visual representation of the data.
If the question is appropriate for SQL generation, Xpert will generate a SQL query from the text, run it to retrieve data, and use that data and the rewritten question to generate a text response. This process lets users ask follow-up questions—users can continue to ask questions based on the text response provided. Xpert offers a conversational and interactive experience because users can continue to ask questions and receive answers in near real time.
SQL generation for data retrieval
Text-to-SQL generation is a powerful tool for applications that require data retrieval from databases based on user input. Large Language Models (LLMs) make it possible to generate accurate SQL queries and provide natural language responses to users, which simplifies the data retrieval process. Text-to-SQL generation is a crucial aspect of Xpert that enables the conversion of natural language queries into structured SQL queries.
Figure 2. Example of a user question that requires SQL generation
The Text-to-SQL step occurs after the router predicts a rewritten user question for SQL generation. Once the LLM generates the SQL query, it is run against a Snowflake database to retrieve the required data. The retrieved data is then used to generate a text response corresponding to the user’s original query. This text generation process involves converting the structured data into a natural language response for the user.
Python code generation for data visualization
Xpert can generate visualizations based on user questions through text-to-Python generation—transforming a natural language prompt into executable Python code. This feature is valuable to bpx employees who regularly face the challenge of analyzing complex well production data to drive informed decision-making.
Figure 3. Example of a user question that requires Python code generation
Users describe their objectives in natural language and do not need prior knowledge of Python. The text prompt is translated into Python code and run to deliver the desired visualization.
The system retrieves the relevant dataset from the Snowflake database, loading it into a Pandas DataFrame. The generated Python is run against the dataset to create plots that highlight production trends. This approach empowers employees of all skill levels without a steep learning curve.
Multi-turn conversation
Multi-turn conversation lets users engage in natural back-and-forth exchanges, providing a seamless and intuitive user experience. While analyzing production data from wells, instead of restating the entire context with each new question, users can simply ask follow-up questions.
Figure 4. Letting users ask follow-up questions; to answer those, Xpert uses information in previously asked questions
The primary challenge in implementing multi-turn conversation for code generation is maintaining a coherent understanding of the user’s question across multiple turns. The system must effectively manage the conversational context, which includes tracking previous questions, and any modifications or clarifications made by the user in the follow-up questions. The final output should accurately reflect the user’s most recent query while considering previous conversation.
Xpert uses the conversational context from previous interactions to rewrite the question and accurately reflect the user’s intent. After a router predicts whether the request requires SQL or Python code generation, the code is generated and run, providing a response to the user. Users can then ask follow-up questions. This iterative process enhances the user experience and analyzes well production data more accurately.
Outcome
bpx built the Xpert generative AI solution on Amazon Bedrock to improve how employees interact with data, and the company foresees significant reduction of manual effort in analyzing dashboards. Users across the organization use the solution to analyze production data quickly through natural language, freeing up employees to focus on other critical tasks. bpx has achieved success in the initial implementation of this generative AI solution and plans to extend generative AI into other use cases.
“The generative AI solution we’ve built alongside the AWS Generative AI Innovation Center is bleeding edge and incredibly exciting,” says Matthew McElhaney, bpx’s head of data science and AI. “The bpx AI team will use the knowledge gained and AWS tooling to reach the next steps in development and drive significant value for bpx.”
For additional AWS energy customer generative AI use cases on AWS, please check out Reinventing energy with generative AI. You’ll learn more about how companies like Enel and Everus are using generative AI and Amazon Bedrock in the energy industry. If you’d like to work with the AWS Generative AI Innovation Center or have other ideas and feedback, please reach out to us or leave a comment.