Type-aware RAG method translates natural-language requirements into executable optimization code by enforcing types and dependencies. AI relevance: enhances LLM reliability for automated industrial modeling.
Type-Aware Retrieval-Augmented Generation (RAG) with Dependency Closure is a method designed to translate natural-language requirements into solver-executable optimization code by enforcing modeling entity types and minimal dependency closure to ensure code executability. Unlike conventional RAG approaches that index unstructured text, this method constructs a domain-specific typed knowledge base by parsing heterogeneous sources—such as academic papers and solver code—into typed units and encoding their mathematical dependencies in a knowledge graph.
Given a natural-language instruction, the system performs hybrid retrieval and computes a minimal dependency-closed context, defined as the smallest set of typed symbols required to generate solver-executable code, through dependency propagation over the graph. This approach specifically addresses common failures of large language models (LLMs) in industrial optimization, such as generating non-compilable code due to missing declarations, type inconsistencies, and incomplete dependency contexts.
The method has been validated on two industrial optimization cases: demand response in battery production and flexible job shop scheduling. In the first, it successfully generated an executable model incorporating demand-response incentives and load-reduction constraints, achieving peak load shaving while preserving profitability—where conventional RAG baselines failed. In the second, it consistently produced compilable models that reached known optimal solutions, demonstrating cross-domain generalization. Ablation studies confirm that type-aware dependency closure is essential for avoiding structural hallucinations and ensuring executability, a critical step toward deploying LLMs in complex engineering tasks.
This approach exemplifies how retrieval-augmented generation can enhance LLM reliability in specialized, constraint-intensive domains by integrating structured knowledge and dynamic context retrieval, thus bridging the gap between natural language and formal, executable modeling
This paper addresses the critical challenge of automated industrial optimization modeling by introducing a Type-Aware Retrieval-Augmented Generation (RAG) framework designed to translate natural-language requirements directly into solver-executable code. While Large Language Models (LLMs) possess strong capabilities in semantic understanding, they often struggle with the rigorous syntax, variable consistency, and logical formalism required by optimization solvers (e.g., Gurobi, CPLEX). The authors propose a system that grounds the generative process in a structured knowledge base, ensuring that the generated code adheres to the specific type systems and semantic constraints inherent in mathematical programming languages.
The key technical innovation of this work lies in its enforcement of "dependency closure" during the retrieval and generation phases. Instead of treating code snippets in isolation, the method traces the dependencies of variables and constraints, ensuring that if a specific constraint is retrieved, all related variable definitions, sets, and parameters are also included and contextually consistent. By integrating type-awareness into the retrieval mechanism, the system prevents common errors such as type mismatches or undefined references, which typically plague LLM-generated code. This approach allows the model to construct complete, mathematically sound formulations that reflect the complex interdependencies of industrial problems.
This research matters significantly because it represents a substantial leap toward reliable, automated decision support systems in industrial settings. By bridging the gap between unstructured natural language inputs and structured, executable optimization models, it democratizes access to advanced operations research tools, allowing non-experts to leverage high-performance solvers. Furthermore, the methodology offers a blueprint for improving LLM reliability in other highly structured domains, demonstrating that enforcing symbolic constraints (like types and dependencies) is essential for moving AI from generating text to generating functional, executable logic.
This paper introduces a type-aware Retrieval-Augmented Generation (RAG) framework designed to translate natural-language (NL) requirements into executable optimization models for industrial applications. Unlike traditional RAG systems that focus on retrieval and generation without strict semantic constraints, this approach enforces type safety and dependency closure to ensure generated code adheres to mathematical and computational correctness. By leveraging a knowledge base of formal optimization problem structures (e.g., variables, constraints, objectives) and enforcing constraints via type checking and dependency resolution, the system produces solver-executable code (e.g., in AMPL, Pyomo, or Gurobi) directly from NL inputs. The method addresses a critical gap in AI-driven modeling: the reliability of generated optimization code, which is often brittle due to ambiguous or incomplete NL specifications.
The paper’s key contributions include: 1. Type-Aware Generation: A type system that maps NL concepts to formal optimization constructs (e.g., decision variables, parameters, constraints), reducing semantic ambiguity. 2. Dependency Closure: Ensuring that generated models are mathematically well-formed by resolving dependencies between components (e.g., constraints referencing undefined variables). 3. Solver Executability: Output code that can be directly passed to industrial solvers, improving automation for domains like supply chain, scheduling, and resource allocation.
This work is significant for industrial AI applications where optimization models are frequently hand-crafted by domain experts. By automating the translation of NL requirements into correct, executable code, the framework enhances productivity and reduces errors in model development. It also advances the reliability of LLMs in high-stakes domains where incorrect generations could lead to suboptimal or infeasible solutions. The approach aligns with broader trends in neurosymbolic AI, where symbolic constraints (e.g., type systems) guide neural generation to produce verifiable outputs.