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 questionFigure 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 generationFigure 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 generationFigure 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 questionsFigure 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.

Matthew McElhaney

Matthew McElhaney

Matthew McElhaney serves as the head of data science and AI for bpx. Matt oversees data science and AI, as well as software, GIS, and reporting. His recent focus is on implementing and scaling innovative generative AI solutions for bpx. Matt has 10 years of experience in the energy industry with roles focusing on operations, innovation, and data science. Prior to joining the industry, he served as an infantry officer in the US Army. Matt has a BS in bioengineering from the University of Pittsburgh, an MBA from Carnegie Mellon University, an MS in petroleum engineering from Texas A&M, and an MS in information and data science from UC Berkeley.

Amruta Karnik

Amruta Karnik

Amruta is a Senior Solutions Architect with AWS Energy. She enjoys working with customers mapping out their Data Analytics journey. She has development experience building enterprise software applications and integrations. Her hobbies include going scuba diving with her family.

Ayush Rastogi

Ayush Rastogi

Ayush Rastogi is a Senior Machine Learning Engineer at bpx energy with over eight years of specialized experience in data analytics within the oil and gas sector. With a background in integrating physics-based and data-driven algorithms, he specializes in solving complex business challenges. Currently, he is focused on the implementation of generative AI for enterprise-level applications. His work involves leveraging advanced AI technologies to optimize exploration and production processes, enhance predictive modeling, and improve decision-making through statistically driven data analysis. Ayush holds a Ph.D. in Petroleum Engineering from the Colorado School of Mines, where his research significantly contributed to the advancement of mechanistic modeling and predictive analytics. He is also one of the co-authors of the book 'Machine Learning in the Oil and Gas Industry'.

Chuanyue Shen

Chuanyue Shen

Chuanyue Shen is a Machine Learning Engineer at bpx, where she designs, develops, and deploys AI solutions. She collaborates with cross-functional teams to leverage Generative AI, Computer Vision, and Machine Learning, driving innovation to improve operational efficiencies and deliver business value. Chuanyue obtained a PhD in Civil Engineering and a Master in Computer Science from the University of Illinois at Urbana-Champaign.

Mu Li

Mu Li

Li is a Senior Manager of Solutions Architect with AWS Energy. He’s passionate about working with customers to achieve business outcomes using technology. Li has worked with customers to launch the Production Monitoring & Surveillance solution, deploy OpenLink Endur on AWS, and implemented AWS-native IoT and Machine Learning workloads. Outside of work, Li enjoys spending time with his family, following Houston sports teams, and reading on business and technology.

Nkechinyere Agu

Nkechinyere Agu

Nkechinyere Agu is an Applied scientist at the AWS Generative AI Innovation Center, where she works with various organizations in multiple industries to develop AI solutions. Her work focuses on various areas, including computer vision, Natural Language Processing and Knowledge Representation and Reasoning. Nkechinyere obtained her PhD in Computer Science from Rensselaer Polytechnic Institute.

Shinan Zhang

Shinan Zhang

Shinan Zhang is an Applied Science Manager at the AWS Generative AI Innovation Center. With over a decade of experience in machine learning and Natural Language Processing, Shinan has worked with large organizations from diverse industries to solve business problems with innovative AI solutions and bridge the gap between research and industry applications.

Tryambak Gangopadhyay

Tryambak Gangopadhyay

Tryambak Gangopadhyay is an Applied Scientist at the AWS Generative AI Innovation Center, where he collaborates with organizations across a diverse spectrum of industries. His role involves researching and developing generative AI solutions to address crucial business challenges and accelerate AI adoption. Prior to joining AWS, Tryambak completed his PhD at Iowa State University.

Yanru Xiao

Yanru Xiao

Yanru Xiao is an Applied Scientist at the Amazon Generative AI Innovation Center, where he builds AI and machine learning solutions for customers’ real-world business problems. He has worked in several fields, including manufacturing, energy, and agriculture. Yanru obtained his PhD in Computer Science from Old Dominion University.