Overview
In Model-Based Systems Engineering (MBSE), the Object Constraint Language (OCL) is a formal language used to define precise rules and invariants that a system model must satisfy. While essential for system integrity, writing OCL is notoriously difficult, requiring deep expertise in both system architecture and formal syntax. Large Language Models (LLMs) offer a potential solution for automating OCL generation, but they face a significant "context window" challenge: system meta-models are often too large to fit entirely within a single prompt.
This paper explores the use of Retrieval-Augmented Generation (RAG) to bridge this gap, investigating how different retrieval strategies impact the accuracy of OCL generation from natural language requirements.
Methodology: The RAG Pipeline
The researchers developed a RAG pipeline centered on Meta-Llama-3-8B-Instruct. The workflow involves taking a natural language specification and retrieving the $k$ most relevant "atomic" chunks (classes, associations, or enums) from the system's meta-model to provide the LLM with necessary context.
The study systematically compared three retrieval strategies:
- BM25 (Lexical): A traditional keyword-matching approach.
- BERT-based (Dense Semantic): Uses contextual embeddings to find conceptually similar chunks.
- SPLADE (Sparse Semantic): A hybrid approach that leverages learned term expansions to find relevant context even when exact keywords are missing.
Experimental Results
The evaluation was conducted on a dataset of "hard" instances where meta-models exceeded 50 chunks, making retrieval strictly necessary. The results highlighted a critical "noise threshold": providing more context (higher $k$) does not always lead to better results.
Key Findings
- SPLADE is the Optimal Strategy: SPLADE at $k=10$ achieved the highest accuracy, with a Mean Cosine Similarity of 0.9360. This outperformed the no-retrieval baseline (0.9338) and specialized graph-based methods like PathOCL (0.9251).
- The Failure of Lexical Search: BM25 performed significantly worse than the baseline, particularly as more context was added. At $k=50$, its similarity score dropped to 0.9133, proving that irrelevant context can actively confuse the model.
- Precision over Volume: For both BM25 and SPLADE, performance peaked at lower $k$ values. This suggests that for domain-specific tasks like OCL, a small amount of highly relevant context is far more valuable than a large, noisy context window.
Conclusion and Future Work
The study demonstrates that RAG is a viable path for automating OCL generation, with sparse-vector retrieval (SPLADE) offering the best precision. However, the authors note that text similarity metrics do not guarantee functional correctness. Future research will focus on "smarter" chunking strategies that preserve structural relationships within the meta-model and evaluating the logical validity of the generated OCL code.
Summary updated