@Override
        public ExpressionNode transform(ExpressionNode node, TransformContext context) {
            var orig = node;
            if (node instanceof ReferenceNode r) {
                var ref = r.reference();
                if (ref.name().equals("onnx") || ref.name().equals("onnxModel")) {
                    logger.fine("consider replacing: " + ref);
                    var m = getModel(ref.simpleArgument().orElse(null));
                    if (m != null) {
                        // Load the model (if not already loaded) to extract inputs
                        m.load();
                        var expr = m.getExpressionForOutput(ref.output());
                        if (expr != null) {
                            logger.fine("Replacing " + node + " => " + expr);
                            node = expr;
                            for (var inputSpec : m.inputSpecs) {
                                var old = declaredTypes.get(inputSpec.source);
                                if (old == null) {
                                    declaredTypes.put(inputSpec.source, inputSpec.wantedType);
                                } else if (! old.isAssignableTo(inputSpec.wantedType)) {
                                    throw new IllegalArgumentException("Conflicting types needed for " + inputSpec.source + "; " + old + " cannot be assigned to " + inputSpec.wantedType);
                                }
                            }
                        } else {
                            logger.fine("no output named " + ref.output() + " from " + m);
                        }
                    } else {
                        logger.fine("no onnx model named " + ref.simpleArgument());
                    }
                }
            }
            if (node instanceof CompositeNode c) {
                node = transformChildren(c, context);
            }
            if (node != orig) {
                logger.fine("transformed: " + orig + " => " + node);
            }
            return node;
        }
Programmatically create a model containing functions without constant of function references only
model-evaluation/src/main/java/ai/vespa/models/evaluation/Model.java