Cad code generation method based on multi-granularity design feature coverage
Patent Information
- Application Number
- CN202610659033.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-13
- Publication Date
- 2026-08-18
AI Technical Summary
如果需要针对所有复杂的设计需要都寻找一个非常高相似的样本提供给大模型参考,这对于检索数据库的大小和检索效率都有极高的要求
[0017]有益效果:本发明提供的方法及系统,相较于先前依赖单一样本相似度检索的方法,具有以下优点:通过优化“特征覆盖度”而非“整体相似度”,可以在较少量的样本示例下达到极高的生成准确率,面对较为复杂的3D模型生成任务能够在几何相似度上更接近设计正确值;有效解决了复杂设计规范中异构特征(如多几何体+布尔运算+对称复制)组合复用,导致无法通过样本间检索得到高相似样本的问题。通过组合覆盖最大化了基础数据集对于示例的收益;组件提取与覆盖度优化框架不依赖于特定模型权重,在不同的大语言模型上均可以直接接入使用。而且检索数据库可以根据需求场景进行扩展和修改。
Smart Images

Figure CN122595406A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a CAD code generation method based on multi-granularity design feature coverage, belonging to the fields of artificial intelligence and industrial software technology. Background Technology
[0002] Computer-aided design (CAD) is the foundation of modern manufacturing engineering design. It defines 3D models through precise geometric descriptions and topological relationships, providing core data support for mechanical simulation, thermodynamic analysis, and CNC machining. With the evolution of industrial digitalization, CAD modeling is shifting from traditional interactive graphical user interfaces to a code-driven parametric modeling paradigm. In this paradigm, complex geometric entities are abstracted into dynamic logic defined by underlying domain-specific languages or programming APIs, thereby achieving high model reusability and automation.
[0003] However, parametric modeling places extremely high demands on practitioners' programming skills and domain knowledge. In recent years, Large Language Models (LLMs) have shown significant potential in the field of automated code generation and are considered a high-potential solution for lowering the barrier to entry in CAD design and improving manufacturing capabilities. However, due to the highly specialized nature of the CAD field and the stringent physical constraints in the model generation process, large language models still face serious challenges when directly applied to CAD code generation. The scarcity of domain-specific data hinders adequate model training. Unlike general-purpose programming languages, detailed, parameterized CAD code that can be processed by large language models (such as the Python third-party library CadQuery) is often a core corporate asset or patented design, kept confidential, and rarely shared publicly. This results in small and highly specialized training corpora, causing large language models to perform poorly when handling complex modeling tasks. Even the latest open-source large models have very low code pass rates for complex tasks in zero-shot settings.
[0004] Currently, a common approach to address this challenge is to continuously fine-tune the model on manually annotated CAD datasets. However, this method faces fundamental limitations such as enormous computational resource consumption, high annotation costs, and limited dataset quality.
[0005] Contextual learning (ICL) stands out as a knowledge injection scheme that requires no training, enhancing the performance of large language models by introducing task-specific examples into the input context. Existing technologies primarily employ similarity retrieval methods based on single-sample granularity, directly calculating the most similar examples in the database to the current requirement as references. Effective example retrieval can alleviate the problem of data scarcity. However, when facing tasks like CAD, which have highly reusable basic components and complex feature combinations, directly using traditional techniques to select input examples based on data similarity between samples often fails to ensure that the retrieved example set completely covers all design specifications in the query requirements, leading to model generation failure due to a lack of key knowledge support. Summary of the Invention
[0006] Purpose of the Invention: Industrial design tasks present challenges due to the high reusability, specialization, and scarcity of data. Finding highly similar samples for large models to reference all complex design needs places extremely high demands on the size of the retrieval database and retrieval efficiency. However, using multiple examples to cover a portion of the required features can greatly simplify the entire process. This invention provides a CAD code generation method based on multi-granularity design feature coverage, enabling large models to correctly generate basic parts and assemble them according to certain constraints. Specifically, based on context learning techniques in the field of large language models, it innovatively utilizes the characteristic that complex 3D designs can be deconstructed into highly reusable basic parts: by extracting multi-granularity design specification features, a design specification coverage rate is proposed to quantify the sufficiency of relevant features in examples. This approach aims to overcome the limitations of scarce specialized datasets and improve the marginal benefit of retrieving examples in long-context scenarios. The goal is to achieve high accuracy of basic components in CAD generation tasks using large language models at a lower cost.
[0007] Technical Solution: A CAD code generation method based on multi-granularity design feature coverage. By extracting design features at multiple granularities and optimizing the coverage ratio of feature components, this method can efficiently retrieve a subset of complementary examples with high marginal returns from a large example database when facing complex design specifications. These examples serve as contextual examples for the Large Language Model (LLM) during code generation. This method enables the LLM to acquire complete task background knowledge before code generation and solves the problem of lacking highly similar samples for complex tasks by decomposing shape features.
[0008] Generating target CAD code based on a given design requirements description includes the following steps: Step (1): Obtain the design requirements as the raw input; remove the parts that are irrelevant to the geometric modeling features from the natural language requirement input to obtain the standardized input sequence; Step (2) includes the following: Multi-scale sliding window sampling; set multiple window size sets, continuously slide on the input sequence obtained in step (1) to extract text features and merge them to obtain a feature set, and the different sizes are regarded as design features of different granularities; Construct a complete set of feature components; merge the extraction results from all granularities to obtain a set representing the complete feature representation of the design requirements; and simultaneously perform design feature extraction processing on the database and requirement inputs. Step (3) includes the following: The retrieval is optimized based on the combined coverage of the extracted design feature set. Before the retrieval, the state needs to be initialized: first, the coverage set and the selected sample subset are initialized, and the set that has been covered is set to empty, the set waiting to be covered is equal to the complete query set, and the set of selected samples is set to empty. Candidate samples in the example database are initially screened based on the required feature set; since multiple traversals of the complete database involve a large amount of computation, the initial screening is based on the coverage result of the feature set at the minimum scale, and completely irrelevant samples are deleted. Greedy search maximizes marginal benefit; based on the diminishing marginal benefit property of submodular optimization, greedily select an example from the candidate set that maximizes the weighted score gain of the current covered set and add it to the current selection subset; Iteratively retrieve and expand the example set; repeat the retrieval operation in the greedy search to maximize marginal benefit until the size of the selected example set reaches the preset limit of the number of examples, or the maximum marginal benefit is zero; The selected subset of examples is used as contextual prompts and input into the large language model to generate corresponding editable CAD modeling code and render the model.
[0009] This invention is based on a real CAD code data warehouse and design requirements. Under a context-learning setting, there is a sample database containing design specifications and their corresponding code. Specifically, this includes natural language design description. The corresponding code script and the final rendered model It will also accept a natural language design specification during generation. As input for the query. This natural language design specification. Specifications typically encompass multiple dimensions of the target model's features, including basic geometric elements (such as cylinders and spheres), topological spatial relationships (such as adjacency and symmetry), and binary logic (such as union and intersection). The goal of the CAD code generation task is to utilize a large language model to transform this input specification into an executable CAD script, i.e. ,in This indicates that the specified design logic has been implemented and the code can be executed to render the corresponding model using the engine. The complete example database size is [size missing] when retrieving examples. The overall set of index numbers is gather This represents the index number of the selected sample subset. It selects k groups from this sample set. need and the corresponding correct modeling code The example pairs are then combined to address the current requirements. The complete ICL code generation process can be represented as follows: Multi-scale sliding windows are used to extract multi-granularity features from the input sequence, resulting in query design component sets at different semantic levels. The same extraction algorithm is used to extract candidate example component sets from the example database of natural language specifications and corresponding CAD codes, constructing a query database. The feature coverage ratio between the candidate example subset and the query design component set is calculated. Based on the principle of submodular optimization and according to the information marginal gain maximization criterion, a locally optimal example is iteratively and greedily selected from the example database to synthesize the optimal context example subset. The optimal context example subset is combined with the query input as a prompt, which is then input into the large language model to obtain the parameterized CAD code output by the model. This achieves the automatic conversion of design specifications into executable code.
[0010] The specific process of step (2) is as follows: In order to quantify the overlap between queries and examples at different semantic levels, a structured representation method is introduced to standardize the input. Application size is A sliding window to extract all consecutive... -grams form components to capture heterogeneous information ranging from atomic geometric primitives to complex combinatorial relationships, conforming to natural language design specifications. Decomposed into a collection of design components of varying sizes and granularities The extraction formula is as follows: in, The maximum word length of the input design text. The entire extraction process is equivalent to extracting all sentence segments consisting of n consecutive words from the original input text. To capture design features across semantic levels and balance computational efficiency, the window size n is selected as an exponentially spaced set of sizes. .
[0011] A complete set of design feature components is defined as the union of component sets at all size granularities, as shown in the following formula: In step (3), the calculation method for the feature coverage ratio is first defined as follows: the sample database index set is set as... The selected sample subset is The union of all components that can be covered in the example subset is... .
[0012] Next, the example component set is calculated against the query input component set. coverage ratio First, we obtain the set of demand characteristics. and the intersection that the examples can cover. Then, calculate their respective weighted scores and finally calculate the relative ratio between the two. The specific calculation formula is as follows: The weight calculation function The weight of each feature component in the set is calculated and summed to obtain the overall weight score of the input set. In this invention, the weight of a design feature is equal to the length of its consecutive statements, i.e. In other words, longer and more complex design specification components will receive higher weights to reflect the greater influence of complex topological features. The specific process of selecting and constructing the optimal subset of contextual examples from the entire set of examples is as follows: To constrain the cardinality of the examples... Maximizing the coverage ratio is transformed into finding the optimal subset that maximizes the coverage ratio. Question: This invention employs a greedy algorithm to iteratively and efficiently compute the approximate maximum coverage example set. Specifically, in each iteration, the marginal gain from all unselected candidate examples is calculated. (From the empty set...) We begin by iteratively selecting the example with the maximum marginal gain using the following greedy criterion. Add to collection: Iteratively execute the above formula until the number of selected examples reaches the specified number. Alternatively, the algorithm can exit early when there is no marginal return, and the final output set is the selected set of context examples. This greedy algorithm runs in multinomial time. Internal operation, through the properties of the secondary module, proves that the invention can achieve [the desired result]. The approximation is such that the scheme can achieve at least 63% of the optimal coverage. Under cardinality constraints... When smaller (e.g.) The boundary is more compact, approximately .
[0013] A CAD code generation system based on multi-granularity design feature coverage includes: Multi-granularity feature extraction module: Used to transform the input natural language description into a feature set covering different knowledge levels; Combined Coverage Example Retrieval Module: Used to calculate the feature set coverage between examples and queries, and execute a greedy algorithm to select the optimal combination of examples; Code generation module: encapsulates the filtering examples and query requests, and calls a large language model to generate code scripts based on specific specifications.
[0014] The implementation process and methods of the system are the same and will not be described again.
[0015] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of the CAD code generation method based on multi-granularity design feature coverage as described above.
[0016] A computer-readable storage medium having a computer program / instructions stored thereon, which, when executed by a processor, implements the steps of the CAD code generation method based on multi-granularity design feature coverage as described above.
[0017] Beneficial Effects: Compared to previous methods relying on single-sample similarity retrieval, the method and system provided by this invention have the following advantages: By optimizing "feature coverage" rather than "overall similarity," extremely high generation accuracy can be achieved with a smaller number of sample examples. For more complex 3D model generation tasks, it can more closely approximate the correct design value in terms of geometric similarity. It effectively solves the problem that the reuse of heterogeneous features (such as multiple geometries + Boolean operations + symmetric replication) in complex design specifications makes it impossible to obtain highly similar samples through inter-sample retrieval. Combined coverage maximizes the benefits of the basic dataset for examples; the component extraction and coverage optimization framework does not depend on specific model weights and can be directly integrated and used on different large language models. Furthermore, the retrieval database can be expanded and modified according to the required scenario. Attached Figure Description
[0018] Figure 1 This is a complete flowchart of generating a CAD model from design input according to an embodiment of the present invention; Figure 2 This is a flowchart illustrating multi-granularity design feature extraction based on an input design requirement description, according to an embodiment of the present invention. Figure 3 This is a flowchart illustrating the selection of an example subset based on maximizing the coverage of the design feature set, according to an embodiment of the present invention. Figure 4This is an example of how the present invention is deployed on an end-to-end platform of “input-3D model”. Detailed Implementation
[0019] The present invention will be further illustrated below with reference to specific embodiments. It should be understood that these embodiments are for illustrative purposes only and are not intended to limit the scope of the invention. After reading the present invention, any modifications of the present invention in various equivalent forms by those skilled in the art will fall within the scope defined by the appended claims.
[0020] A CAD code generation method based on multi-granularity design feature coverage is deployed in an end-to-end environment of "natural language requirements - 3D model". (See...) Figure 4 In this environment, the embodiment retrieves several similar examples from a database to help generate solutions for a large model, addressing a complex natural language design requirement environment. The method of this invention integrates multi-granularity feature extraction with a sub-modulus maximization combinatorial optimization algorithm, using quantified "feature sufficiency" to select complementary examples, guiding the large language model to generate high-precision CAD scripts. A complete embodiment process includes the following steps: Step (0): In the actual implementation process, the design requirements obtained are often vague and not detailed enough (e.g., "Please design a chair"), which cannot be directly aligned with the natural language in the database. As shown in Figure 2, it is necessary to first use a large model to perform translation and normalization detailed design completion operations. Step (1): Decompose complex design requirements, extract multi-granularity design components, and construct a set of design features. Develop natural language design specifications for the database and requirements. , Semantic components at different levels are extracted using structured decomposition techniques. Step (2): Fuzzy Natural Language Denoising. Based on the set of commonly used stop words, from the complete original input... Remove geometrically irrelevant parts and remove person and tense from the vocabulary to remove the influence on word roots to obtain a clean set of words. ; Step (3): Multi-scale sliding window sampling. Set a set of sizes with exponential intervals. Slide to extract consecutive words from the processed word sequence. - A collection of gram components, where different sizes are considered as extracting design features of different granularities: Step (4): Construct the complete component set. Merge the extraction results at all granularities to obtain a set representing the complete feature requirements of the design requirement. . The extracted results serve as the query index for the corresponding samples in the database. , The results are used as a query set ; Step (5): Perform combined coverage optimization retrieval based on the extracted design feature set. First, initialize the coverage set and the selected subset. State initialization is required before iterative retrieval. Let the set that has been covered be an empty set, the set waiting to be covered be equal to the complete query set, and the selected example set be an empty set: , S = Step (6): First, preliminary screening of candidate samples. Since multiple traversals of the complete database are computationally intensive and repetitive, completely irrelevant samples can be removed first based on the coverage results of the smallest component set (1-gram). These samples have zero similarity regardless of the granularity of calculation or query, and do not need to participate in the iteration. Step (7): Greedy search to maximize marginal benefit. Based on the diminishing marginal benefit property of submodular optimization, a sample is greedily selected from the candidate set that maximizes the weighted score gain of the current coverage set. Add to the currently selected subset : Simultaneously update the coverage status and candidate set, and delete... The covered elements and the indexes of examples whose contribution was 0 in this round of computation. This reduces the computational complexity in subsequent calculations. Step (8): Iterative solution. Repeat the retrieval operation in step (7) until the size of the example set reaches the preset example limit. Or, the maximum marginal benefit is zero (in which case the choice set is the globally optimal solution): Step (9): Use the constructed context examples to guide the large language model to perform logical reasoning and code synthesis: select overlay example pairs Compared with the current query The data is synthesized by piecing together a fixed template (containing task description and brief background information). The input is then fed into a pre-trained large language model to obtain the answer. Step (10): Extract the Python code block from the feedback result using regular expressions, execute it through a CAD rendering engine (such as CadQuery), and render it as an editable 3D entity to be returned to the user; Step (11): If the CAD code generated in step (10) fails to execute in the rendering engine or the generated geometric entity is invalid, the error message is fed back through dialogue with the large language model, and attempts are made to regenerate until a reasonable result is obtained or the upper limit of the number of dialogue rounds is reached.
[0021] Obviously, those skilled in the art should understand that the steps of the CAD code generation method based on multi-granularity design feature coverage or the modules of the CAD code generation system based on multi-granularity design feature coverage described in the above embodiments of the present invention can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. Optionally, they can be implemented using computer-executable program code, thereby storing them in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the embodiments of the present invention are not limited to any particular hardware and software combination.
Claims
1. A CAD code generation method based on multi-granularity design feature coverage, characterized in that, Generating target CAD code based on a given design requirements description includes the following steps: Step 1: Obtain design requirements as the raw input; remove parts irrelevant to geometric modeling features from the natural language requirement input to obtain a standardized input sequence; Step 2, multi-scale sliding window sampling; set multiple window size sets, continuously slide the window on the input sequence obtained in step 1 to extract text features, merge them to obtain a feature set, and the different sizes are regarded as design features of different granularities. Step 3: Construct a complete set of feature components; merge the extraction results at all granularities to obtain a set representing the complete feature representation of the design requirements; and simultaneously perform design feature extraction processing on the database and requirement input. Step 4: Perform combined coverage optimization retrieval based on the extracted design feature set; before performing the retrieval, the state needs to be initialized: first, initialize the coverage set and the selected sample subset, setting the set that has been covered to an empty set, the set waiting to be covered to be equal to the complete query set, and the set of selected samples to an empty set; Step 5: Initially screen candidate samples in the example database based on the required feature set; since multiple traversals of the complete database involve a large amount of computation, the initial screening is performed based on the coverage results of the feature set at the minimum scale, and completely irrelevant samples are deleted. Step 6: Greedy search to maximize marginal benefit; Based on the diminishing marginal benefit property of submodular optimization, greedily select an example from the candidate set that maximizes the weighted score gain of the current coverage set and add it to the current selection subset; Step 7, iteratively search and expand the example set; repeat the search operation in the greedy search to maximize marginal benefit until the size of the selected example set reaches the preset limit of the number of examples, or the maximum marginal benefit is zero; Step 8: Input the selected sample subset as contextual prompts into the large language model to generate the corresponding editable CAD modeling code and render the model.
2. The CAD code generation method based on multi-granularity design feature coverage according to claim 1, characterized in that, Define a multi-granularity set of dimensions, and apply sliding windows of different sizes to the input requirements to extract all design features as the design feature set under that dimension; Then, the components extracted from all sizes are combined to form a complete set of "design requirements - modeling code" components.
3. The CAD code generation method based on multi-granularity design feature coverage according to claim 1, characterized in that, For a selected sample subset, the design feature components that the set can cover are represented as the union of the sets of each element component; the proportion of the requirements that the sample subset can cover is represented by a weighted benefit score, where the weight of each design feature element is equal to its window size; the specific calculation process is as follows: first, calculate the intersection of the feature components that the sample subset can cover with the set of components corresponding to the design requirements, then calculate the weight score of each element in the intersection, and sum all the weights as the coverage score of the sample subset for the design requirements.
4. The CAD code generation method based on multi-granularity design feature coverage according to claim 1, characterized in that, The iteration criterion for each step of the algorithm for maximizing marginal revenue retrieval is as follows: select an example from the database such that it can provide the maximum marginal revenue to the current selected set until the preset limit on the number of examples is reached. Specifically, the optimization objective is to select the weighted score of the design feature set that the example can cover, and to traverse the current example data set to select the example with the largest new score.
5. A CAD code generation system based on multi-granularity design feature coverage, characterized in that, include: Multi-granularity feature extraction module: Used to transform the input natural language description into a feature set covering different knowledge levels; Combined Coverage Example Retrieval Module: Used to calculate the feature set coverage between examples and queries, and execute a greedy algorithm to select the optimal combination of examples; Code generation module: encapsulates the filtering examples and query requests, and calls a large language model to generate code scripts based on specific specifications.
6. A computer device, characterized in that: The computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of the CAD code generation method based on multi-granularity design feature coverage as described in any one of claims 1-4.
7. A computer-readable storage medium having a computer program / instructions stored thereon, characterized in that: When the computer program / instruction is executed by the processor, it implements the steps of the CAD code generation method based on multi-granularity design feature coverage as described in any one of claims 1-4.