Editor’s introduction
The research evaluates a Retrieval-Augmented Generation pipeline using 500 synthetic optimization problems derived from the Text2Zinc dataset and professional personas. These problems were encoded in a vector database and used to retrieve semantically similar cases to guide an LLM agent during inference. The study compares the RAG-enhanced approach to a baseline LLM model, measuring performance on NL4OPT, MAMO Easy, and MAMO Complex. The results indicate that retrieval of validated synthetic examples enhances structural consistency and solution accuracy. The evidence demonstrates a clear performance gain over baseline models, particularly in complex combinatorial settings.
Introduction
The mathematical modeling of complex problems by imposing constraints and using optimization techniques is one of the core areas in decision support systems across logistics, healthcare, energy, transportation, and supply chain management. Due to an increase in problem size and complexity, large language models have been increasingly used in optimization problems, yet state-of-the-art LLMs struggle to produce accurate models when tasks require strict structure or multi-step reasoning. This paper focuses on improving the accuracy of optimization models generated by an LLM, as greater accuracy enables more efficient decision-making and resource utilization.
The contribution of this work is to enhance the relationship between natural language problem statements and formal optimization models, thus contributing to the development of explainable AI models. By showing that retrieval-augmented generation can greatly improve LLM performance on structured modeling problems, this study paves the way for developing a transparent tool capable of assisting field experts without optimization model language proficiency.
The solution proposed for this issue is based on building a vector database that will contain systematic and formatted data regarding constraint and optimization problems and their solutions. Each problem contains a description written in the form of a natural language statement, a formal description of the problem in the JSON format, and its Python solution using a model library. All datasets are formalized in order to minimize confusion and facilitate quick search. Using the Retrieval-Augmented Generation (RAG) architecture, it is possible to extract semantically similar examples from the vector database, which can serve as in-context cues for an LLM in order to make it produce appropriate solutions.
Research Objectives. This study pursues three concrete objectives: (1) to construct a diverse, validated synthetic dataset of constraint and optimization problem-solution pairs suitable for use as a retrieval corpus; (2) to design and implement a RAG-based inference pipeline that retrieves semantically similar solved problems and uses them to guide LLM output; and (3) to empirically measure the accuracy improvement conferred by RAG augmentation relative to a direct LLM baseline across multiple publicly available benchmarks.
Constraint satisfaction and optimization problems formulated in LP, MILP, MINLP, and CP can be investigated using this approach. This will be tested using three publicly available benchmark problems, using one base model (Qwen 3 30B Instruct), and 500 generated instances. To apply the results beyond this particular type of models, solver backends, and types of constraint satisfaction and optimization problems, further testing needs to be performed. The data are artificially created. Solver scripts have been checked for compilation and execution, but correctness of all optimality certificates provided cannot be independently confirmed by domain experts.
Optimization and Constraint Programming Overview
Optimization methods and Constraint Programming provide the mathematical basis to tackle complicated decision-making tasks in areas like logistics, manufacturing, energy models, health, and transport. Some widely used paradigms in modeling these complex decision tasks include Linear Programming (LP), Mixed-Integer Linear Programming (MILP), Constraint Programming (CP), and Mixed-Integer Nonlinear Programming (MINLP).
A problem can be represented in terms of linear objectives and constraints in both LP and MILP, with the added ability in MILP for integer or binary variables. The approach in CP focuses on search with guidance from constraint satisfaction, rather than linear constraints. The addition in MINLP of nonlinear terms and mixed integrality significantly increases difficulty in computation compared with the constrained format.
Although small inaccuracies in a model formulation may result in a model being unfeasible, suboptimal, or inconsistent, these issues trigger interest in an area of AI-assisted modeling, whereby language models may be useful in speeding up model formulation and enabling non-experts to perform formulations.
Language Models for Mathematical Reasoning
Large Language Models (LLMs) such as GPT-3/4, LLaMA, Qwen, and Mistral have been making great strides in natural language understanding and code synthesis and reasoning. It was observed that the LLMs could generate algebraic proofs and code and could also handle solvers and symbolic engines. Still, mathematical proof and constraint reasoning pose a great challenge.
Since optimization problems necessarily involve some degree of structured, internally consistent output – typically given in terms of JSON schemas, algebraic expressions, and solver-ready Python code – LLMs are prone to falling short of the desired degree of precision when using just internal knowledge.
Retrieval-Augmented Generation (RAG)
Retrieval-Augmented Generation (RAG) is a combination of neural text generation and a process of external knowledge retrievals. Before the LLM produces an output, it queries a vector database to yield the most semantically relevant documents or examples. Then, it uses these documents or examples to ground its generation process. Thus, it cuts down on hallucinations and keeps it structured.
These successes indicate the promise of RAG for optimization modeling, where a RAG-powered LLM can reuse proven formulation templates, avoid common pitfalls such as missing constraints or improper domains, and produce solver-ready code more reliably than zero-shot inference alone.
Seed Problems from Text2Zinc
We first sample 500 descriptions of natural language problems from the Text2Zinc corpus. These descriptions form a kind of anchor at the semantic level for the data set and introduce varied scenarios related to scheduling, allocation, routing, and other areas of optimization.
All descriptions will be considered purely a semantic starting point. Instead of simply reusing the descriptions, we will use these descriptions as a driving mechanism for our persona generation and problem synthesis, thereby allowing for a new dataset inspired by, but not a copy of, the original Text2Zinc solutions.
Python Solution Generation
The final step of building the dataset involves creating the executable Python code corresponding to each JSON problem. Unlike in a fixed-choice solver configuration, here the LLM has the capability of choosing the appropriate optimization method and/or constraint programming library (MILP, OR Tools, PuLP, LP) depending on the nature of the specific problem. This choice has been made with due consideration to real-world modeling practices.
Dataset Cleaning
After the creation of the JSON problem descriptions, along with the Python coding, a data cleaning and validation cycle was performed to not only guarantee the syntactic correctness of the dataset but also its semantic relevance to be used at the retrieval and modeling levels. There were two major processes performed at this phase, namely (i) normalization of Unicode artifacts and mathematical symbols, and (ii) correction of unstable example instances within solver coding scripts.
Unicode Normalization in JSON Problem Files
The JSON math problems produced by LLM contained occasional use of unicode symbols representing math operators, signs, or fancy punctuation (such as em dashes, smart quotes, subscript letters, or fancy inequality signs). While these are acceptable in natural text, they will interfere with either parsing, vectorizing, or validating JSON schema.
We replaced these characters for all 500 json files and validated that all resulting files were valid to ensure full compatibility with the embedding and RAG pipeline. This ensured that we have a fully normalizing dataset with no unicode artifacts.
Stabilizing Example Instances in Python Solutions
A second problem arose because of the generation of Python solution scripts by the LLM. In some instances, random numerical information was introduced by the LLM into these sample instances by employing random generators or simply random coefficients. This add-in introduced a great deal of variability into the models produced by presenting infeasible solutions, problems without bounds, or trivial solutions for which there was little point in exercising a given formulation.
This improvement made sure that every solution script in the final dataset executes successfully at the end of each run. This means that these solution scripts could be used as genuine ground-truth exemplars for retrieval-based generation studies, irrespective of which underlying optimization library in Python they use.
Exploratory Data Analysis
Before integrating the dataset into the retrieval-augmented generation pipeline, we conducted an exploratory data analysis (EDA) to assess dataset completeness, structural consistency, and solver executability. A preliminary file-level inspection confirmed one-to-one correspondence across all 500 personas, JSON problem files, and Python solver scripts. All JSON files were parsed to verify syntactic correctness, and no malformed files were observed following the Unicode normalization step, confirming the dataset is fully machine-readable and suitable for automated embedding and retrieval.
Solver Executability and Compilation Analysis
To assess the reliability of the Python solution scripts, we performed a static compilation check on every solver file using Python’s built-in compilation utilities. Each script was evaluated for syntactic correctness without executing the solver itself. The results indicate that all solution files successfully compile, demonstrating that the generated code is syntactically valid and free from import or definition errors.
This compilation-based analysis serves as a conservative lower bound on solver correctness: while successful compilation does not guarantee feasibility or optimality, failed compilation would immediately disqualify a solution from serving as a usable ground-truth exemplar. The absence of compilation failures provides strong evidence that the dataset is suitable for use in retrieval-augmented code generation experiments.
Distribution of Problem Characteristics
We further examined high-level characteristics of the dataset to ensure diversity and balance across modeling styles. Problem metadata fields were analyzed to study the distribution of model types (e.g., LP, MILP, CP), the number of constraints per problem, and the variety of decision variable definitions. The majority of problems contain multiple constraints (typically three or more), aligning with the intended focus on non-trivial, multi-constraint optimization tasks.
Additionally, persona descriptions were inspected for length and consistency. All personas satisfy the enforced structural constraints (single paragraph, multiple sentences, profession-centric framing), resulting in stylistically uniform but semantically diverse natural language contexts. This consistency is important for isolating the effect of semantic content during vector retrieval.
Research Design
This study adopts a computational experimental design. The experiment is non-randomized and purely computational: no human subjects are involved, and all data are synthetically generated or drawn from publicly available benchmark corpora. The study is structured in two stages. The first stage is constructive: a synthetic dataset of 500 optimization problem-solution pairs is built, cleaned, and indexed into a vector database. The second stage is evaluative: a RAG-augmented inference pipeline is compared against a direct LLM baseline across three benchmark datasets (NL4OPT, MAMO Easy, and MAMO Complex) using a single held-out set of 25 test queries per benchmark. This within-condition comparison isolates the effect of retrieval augmentation while holding the base model, prompt structure, and evaluation metric constant.
Ethical Considerations
This study does not involve human participants, personal data, or sensitive information of any kind. All optimization problem descriptions are either synthetically generated by a language model or derived from publicly available academic datasets (Text2Zinc, NL4OPT, MAMO). No proprietary data, private communications, or individually identifiable records were used at any stage of the research. The use of GPT-5/ChatGPT 5.0 for synthetic data generation was conducted in accordance with the applicable terms of service. All generated datasets and evaluation results are intended for open scientific reporting. No conflicts of interest or dual-use concerns are associated with the subject matter of this work.
Semantic Gateway for Retrieval Filtering
While retrieved examples can ground generation effectively, semantically similar problems may differ in underlying optimization structure, causing injected context to mislead rather than help. To address this, we introduce a semantic gateway that filters retrieved context before generation.
The gateway controls only whether retrieved fields are populated in the downstream prompt—the agent graph structure is unchanged, so rejections cleanly reduce to baseline inference. This is motivated by prior work showing that unfiltered retrieval can introduce misleading context when semantic similarity does not imply structural equivalence.
Experimental Setup
We conducted experiments using 25 test queries randomly sampled from domains not represented in our training corpus. Each query described a unique optimization problem in natural language, requiring the system to generate both a formal problem formulation and executable Python solver code.
All experiments were conducted using the Qwen 3 30B Instruct model with consistent parameters across both baseline and RAG-enhanced conditions. For the RAG-enhanced approach, we retrieved the top-3 most semantically similar examples from our vector database of 500 synthetic optimization problems.
Performance Comparison Across Datasets
The RAG-enhanced approach demonstrates substantial improvements across all three datasets. For NL4OPT Dataset, accuracy improved by 32 percentage points (from 40% to 72%), representing an 80% relative improvement. For MAMO Easy Dataset, accuracy increased by 16 percentage points (from 40% to 56%), representing a 40% relative improvement. For MAMO Complex Dataset, accuracy improved by 24 percentage points (from 32% to 56%), representing a 75% relative improvement.
Comparison with Prior Work
Our RAG-enhanced approach achieves 72% accuracy on NL4OPT, outperforming the BART baseline (61.0%) and GPT-4 zero-shot (63.3%) reported by Ramamonjison, Yu, Li, and colleagues in the NL4Opt competition. While the competition’s winning ensemble approach achieved 89.9%, it required extensive fine-tuning and ensemble methods, whereas our approach uses a smaller base model (Qwen 3 30B) with retrieval augmentation. On the MAMO datasets, our RAG-enhanced system achieves 56% accuracy, demonstrating consistent performance across diverse problem types. This demonstrates that retrieval augmentation can provide substantial improvements over zero-shot approaches and can approach the performance of heavily fine-tuned systems while using smaller, more accessible models.
Discussion
The current paper sought to test the possibility that a Retrieval-Augmented Generation system, built on a synthetic dataset consisting of 500 optimized problems, can lead to an increase in LLMs’ accuracy in constraint/optimization modeling tasks. It was shown that the RAG approach is superior to a simple agent baseline model by 80%, 40%, and 75% in NL4OPT, MAMO Easy, and MAMO Complex, respectively.
The following implications may be inferred from our experiments regarding the use of AI for decision-making. First, our results prove that the retrieval augmentation method can function as a viable substitute for fine-tuning models: without altering any parameters, the RAG framework obtained better performance than multiple zero-shot and few-shot baselines described in existing studies on the NL4OPT dataset. Second, the improvement of performance on the MAMO Complex set, which contains structurally complicated tasks, indicates that retrieved samples play an especially important role when there are ambiguities and multiple steps involved in modeling the task. Third, the persona-based generation of synthetic datasets proves to be a reliable approach to obtaining diverse training and retrieval datasets.
The three objectives set out at the beginning of the research were fulfilled. First, a synthetic dataset with 500 pairs of problem-solution combinations was developed, verified, and indexed. A vector database on top of which a Chroma filter was implemented proved successful in improving the accuracy of retrieving samples. Finally, the entire pipeline proved its effectiveness in improving performance by providing consistently better results against all benchmarks.
Several aspects should be considered in future research endeavors. Scaling up the size of the synthetic collection to beyond 500 problems (especially with more MINLP and CP problem types) is expected to further enhance the quality of retrievals from difficult benchmark problems. Evaluating fine-tuning on top of the synthetic dataset as a supplementary approach to retrieval could also lead to performance improvements. It should be noted that the selected threshold parameters (0.70 and 0.88) were determined empirically; thus, conducting an extensive ablation study could provide principled criteria for selecting them.
Some issues with the study need to be noted, however. Firstly, there were only 25 test queries used for the benchmark. While this number is enough to observe trends, it does not give much statistical power. Secondly, the synthetic dataset was created with the help of one LLM (GPT-5/ChatGPT 5.0). This may lead to biases in problem design and formulation favoring the retrieval of similar problems. Thirdly, executability was determined by compilation alone; hence, there is no guarantee that the script provides optimal or even feasible answers. Finally, all the experiments were conducted with the help of one model (Qwen 3 30B Instruct).


