R. Larraz, CEPSA, Madrid, Spain
In Part 1 of this article (September 2024), prompt engineering was introduced as a powerful technique for leveraging large language models (LLMs) like ChatGPT, Claude or GPT-4 in the hydrocarbon and green molecules processing industries. Prompt engineering elaborates precise instructions to guide LLMs towards generating specific, desired outputs, and offers significant potential for optimizing processes, solving complex problems and improving operational efficiency in refineries and petrochemical plants.
However, it is crucial to understand the limitations of LLMs and prompt engineering. These models are trained on data with a specific cutoff date, beyond which they lack knowledge of recent events or technological advancements. This limitation can be particularly problematic in rapidly evolving fields like renewable energy or innovative refining technologies. Additionally, LLMs may sometimes generate "hallucinations"—plausible-sounding but entirely fabricated information—which is especially concerning in technical fields where accuracy is paramount.
To address these limitations and enhance the reliability of AI-generated insights, several strategies have emerged. For instance, prompt caching involves storing and reusing successful prompts that have yielded accurate and useful results. Some AI platforms allow users to upload specific documents or datasets, which the LLM can then reference when generating responses. However, one of the most promising methods is retrieval-augmented generation (RAG).2
RAG combines the language model with an external knowledge base or information retrieval system. When a query is made, the system first retrieves relevant information from its current database and then uses this information to augment the LLM's response. This approach allows the AI to access the most recent technical specifications, safety regulations, best practices in the industry or even plant data, ensuring that the generated content is both accurate and compliant with current standards.
When a query is made to the LLM, the retrieval system fetches the most recent and relevant data, which is then incorporated into the prompt. This allows the LLM to provide analyses and recommendations based on the current state of the process, rather than relying solely on historical or static information.
Developing an effective RAG system for a refinery requires a comprehensive approach that integrates various components. While developing such a RAG system represents a significant investment, its potential to enhance operational efficiency, decision-making and safety in refinery operations can offer substantial returns.
The information included in this article is theoretical and does not correspond to any real process or situation. It is only shown to illustrate the potential capabilities of LLMs and should not be used in any way.
As already explained, RAG is a technique that combines LLMs with an information retrieval system to improve the accuracy and relevance of generated responses. RAG enables the LLM to provide responses based on the most recent technical specifications, safety regulations and best practices in the industry, ensuring that the generated content is both accurate and compliant.
Integrating RAG into LLMs for HCs and green molecules processing, as shown in FIG. 3, enables more accurate, relevant and trustworthy AI outputs, avoiding hallucination phenomena. Additionally, the LMM requires no modification, which is a complex and costly task. The procedure is as follows.
Data indexing:
A database of relevant and reliable information is created
This information is indexed to facilitate quick searches
Query processing:
When a question or prompt is received, the system analyzes the query
Information retrieval:
The retrieval system searches the indexed database for information relevant to the query
It selects the most pertinent passages or documents
Context incorporation:
The retrieved information is added to the prompt that will be sent to the LLM
This provides additional, specific context to the model
Response generation:
The LLM processes the enriched prompt (original query + retrieved information)
It generates a response based on its training and the provided context
Post-processing:
The response may be filtered or refined to ensure its quality and relevance
User presentation:
The final response is delivered to the user.
This process allows LLMs to generate more accurate and well-grounded responses by combining their general knowledge with specific and up-to-date information from the retrieval system. This helps to mitigate hallucinations and provides more current and context-specific answers.
In Part 2, the practical applications of these advanced prompt engineering techniques in various aspects of refinery operations will be explored. Examples include key areas where RAG implementation with specific plant information would be highly beneficial.
Process unit optimization. In units such as atmospheric distillation, fluid catalytic cracking (FCC) or hydrodesulfurization, well-designed prompts can guide AI to suggest precise adjustments in operating parameters, improving yield and product quality.
Example for an FCCU:
“Analyze the following FCCU parameters:
Reactor temperature: 535°C
Catalyst-to-oil ratio: 5.5
Regenerator pressure: 2.8 bar
Current conversion: 75%
Objective: Increase propylene production by 3%, considering only operational actions and pointing out possible bottlenecks of the unit. Provide recommendations to adjust operating parameters, considering the impact on coke and light gas production."
To increase propylene production by 3% in an FCCU, analyze the given parameters and provide recommendations while considering the impact on coke and light gas production. The parameters remain the same as above.
LLM recommendations
Increase reactor temperature
Action: Raise the reactor temperature slightly (e.g., to 540°C–545°C).
Impact: Higher temperatures favor the cracking reactions that produce light olefins like propylene. However, this can also increase coke formation and light gas production.
Adjust catalyst-to-oil ratio
Action: Increase the catalyst-to-oil ratio to around 6.
Impact: A higher catalyst-to-oil ratio enhances the cracking activity, leading to more propylene production. This adjustment may also increase coke production, so it should be balanced carefully.
Optimize regenerator pressure
Action: Maintain or slightly reduce the regenerator pressure, if possible.
Impact: Lower regenerator pressure can improve the regeneration efficiency and reduce coke formation. However, significant changes might affect the overall unit balance.
Potential bottlenecks include:
Coke formation: Increasing temperature and catalyst-to-oil ratio can lead to higher coke production, which might limit the regenerator’s capacity.
Light gas production: Higher temperatures and catalyst activity can also increase the production of light gases, which may require adjustments in the gas handling system.
Heat balance: Changes in operating conditions can affect the heat balance of the unit, potentially requiring adjustments in the heat exchangers and other related equipment.
Summary. To achieve a 3% increase in propylene production, consider the following operational adjustments:
Increase reactor temperature to 540°C–545°C.
Raise the catalyst-to-oil ratio to around 6.
Maintain or slightly reduce regenerator pressure.
Monitor the impact on coke and light gas production closely and be prepared to make further adjustments to manage these effects. Balancing these parameters will help optimize propylene yield while minimizing potential bottlenecks. If you need more detailed guidance or have specific constraints, feel free to ask!
Problem solving. When faced with deviations in product quality or process efficiency, prompts can be structured to guide AI in diagnosing root causes and proposing solutions.
Example for a hydrodesulfurization unit:
"The diesel hydrodesulfurization unit shows an increase in product sulfur content from 8 ppm to 15 ppm in the last 48 hr. Current parameters:
Reactor temperature: 345°C
Pressure: 60 bar
LHSV: 1.6 h-1
Hydrogen (H2 )/HC ratio: 300 Nm³/m³
Diagnose possible causes and provide an action plan to restore product quality."
To diagnose the increase in sulfur content and provide an action plan to restore product quality in your a hydrodesulfurization unit, consider the following steps:
Possible causes include:
Catalyst deactivation
Coking: Accumulation of coke on the catalyst surface can reduce its activity.
Metal deposition: Metals from the feedstock can deposit on the catalyst, blocking active sites.
Sintering: High temperatures can cause catalyst particles to agglomerate, reducing surface area.
H2 supply issues
H2 purity: Impurities in the H2 supply can affect the hydrodesulfurization reactions.
H2 partial pressure: Insufficient H2 partial pressure can reduce the effectiveness of sulfur removal.
Feedstock variability
Increased sulfur content: Variations in the feedstock sulfur content can impact the unit’s performance.
Presence of inhibitors: Compounds such as nitrogen or aromatics in the feed can inhibit the catalyst activity.
LLM recommendations: Action plan to restore product quality
Increase reactor temperature:
Action: Raise the reactor temperature by 5°C–10°C.
Impact: Higher temperatures can enhance the desulfurization reactions, improving sulfur removal.
Optimize H2-to-HC ratio (H2/HC):
Action: Increase the H2/HC ratio slightly, if possible.
Impact: Higher H2 availability can improve the hydrodesulfurization efficiency.
Adjust liquid hourly space velocity (LHSV):
Action: Reduce the LHSV to increase the contact time between the feed and the catalyst.
Impact: Longer contact time can enhance the sulfur removal efficiency.
Check H2 supply:
Action: Ensure the H2 supply is pure and at the required pressure.
Impact: Adequate H2 purity and pressure are crucial for effective desulfurization.
Guidelines to identify catalyst problems include:
Monitor pressure drop
Action: Track the pressure drop across the reactor.
Indicator: A significant increase in pressure drop can indicate coking or fouling.
Analyze spent catalyst
Action: Periodically sample and analyze the spent catalyst.
Indicator: High levels of coke or metal deposits can signal catalyst deactivation.
Performance testing
Action: Conduct performance tests to assess catalyst activity.
Indicator: Reduced activity in test results can confirm catalyst deactivation.
Visual inspection:
Action: Perform visual inspections during scheduled shutdowns.
Indicator: Physical changes in the catalyst, such as sintering, can be identified.
Summary. To address the increase in sulfur content:
Optimize H2/HC ratio
Adjust LHSV
Ensure H2 supply quality.
To identify catalyst problems:
Conduct performance tests
Perform visual inspections.
These steps should help restore product quality and plan for a programmed maintenance shutdown. If you need further assistance, feel free to ask.
Predictive maintenance. Well-formulated prompts can help analyze equipment data to predict failures and optimize maintenance programs.
Example for a critical pump:
"Analyze the following vibration and temperature data for a crude feed pump:
Radial vibration: Increased from 2.5 mm/sec to 4.8 mm/sec in 2 weeks
Bearing temperature: Gradual increase from 65°C to 78°C in the last month
Flow: 5% decrease while maintaining the same speed
Assess the risk of failure, suggest additional tests and recommend maintenance actions."
Risk assessment. The data indicates a significant increase in radial vibration and bearing temperature, along with a decrease in flow. These changes suggest potential mechanical issues that could lead to pump failure if not addressed promptly.
Radial vibration
Increase from 2.5 mm/sec to 4.8 mm/sec: This is a substantial rise, indicating possible misalignment, imbalance or bearing wear.
Bearing temperature
Increase from 65°C to 78°C: A gradual rise in bearing temperature often points to lubrication issues, bearing wear or increased friction.
Flow decrease
5% decrease while maintaining the same speed: This could be due to internal wear, impeller damage or partial blockages in the system.
Additional tests include:
Vibration analysis
Detailed vibration spectrum analysis: To identify specific frequencies associated with imbalance, misalignment or bearing defects.
Thermographic inspection
Infrared thermography: To detect hot spots and assess the condition of bearings and lubrication.
Oil analysis
Lubricant analysis: To check for contamination, degradation or metal particles indicating wear.
Flow and pressure testing
Performance testing: To evaluate the pump’s hydraulic performance and identify any deviations from the expected performance curve.
LLM recommendations: Maintenance actions
Alignment check
Action: Perform a precision alignment of the pump and motor.
Reasoning: Misalignment can cause increased vibration and wear.
Bearing inspection and replacement
Action: Inspect bearings for wear and replace, if necessary.
Reasoning: Worn bearings can lead to increased vibration and temperature.
Lubrication system check
Action: Verify the lubrication system is functioning correctly and replenish or replace lubricant, as needed.
Reasoning: Proper lubrication is essential to prevent bearing overheating and wear.
Impeller and internal inspection
Action: Inspect the impeller and internal components for wear or damage.
Reasoning: Damaged impellers can reduce flow and efficiency.
Cleaning and debris removal
Action: Clean the pump internals and remove any debris or blockages.
Reasoning: Blockages can reduce flow and increase operational stress.
Conclusion. Addressing these issues promptly through detailed diagnostics and targeted maintenance actions will help mitigate the risk of pump failure and restore optimal performance.
Takeaways. The answers discussed in Parts 1 and 2 are highly debatable but provide a clear image of the capabilities inherent to LLMs, and the paramount role of prompt engineering as a crucial skill for HC and green molecules-processing professionals. As AI continues to advance, the ability to formulate effective prompts will become an important tool that is always guided by traditional technical knowledge. This synergy between human expertise and AI promises to take efficiency and innovation in the industry to new levels.
By mastering prompt engineering techniques and applying them to specific challenges in HC and green molecules processing, engineers and operators can unlock new insights, optimize complex processes and drive continuous improvement in the industry, especially employing techniques like RAG, which can help in knowledge transfer in an environment of generational replacement. HP
LITERATURE CITED
Lewis, P., et al., “Retrieval-augmented generation for knowledge-intensive NLP tasks,” Cornell University, arXiv:2005.11401v4, April 2021.
Rafael Larraz is a Senior Consultant at Cepsa and Coordinator of the Petroleum Section at the Spanish Institute of Energy. With more than 30 yr of experience in refinery operations and engineering, Dr. Larraz has been involved in numerous large-scale projects, especially for refinery expansion, as well as biofuels production projects. Dr. Larraz holds a PhD in chemical engineering from La Laguna University and an Executive MBA from the IESE Business School.