schema {{ schema_name }} {
    document {{ document_name }}{% if document.inherits %} inherits {{ document.inherits }}{% endif %} {
    {% for field in document.fields %}
        field {{ field.name }} type {{ field.type }} {
            {% if field.indexing %}
            indexing: {{ field.indexing_to_text }}
            {% endif %}
            {% if field.index %}
            index: {{ field.index }}
            {% endif %}
            {% if field.ann or field.attribute %}
            attribute {
                {% if field.ann %}
                distance-metric: {{ field.ann.distance_metric }}
                {% endif %}
                {% if field.attribute %}
                {% for attribute in field.attribute %}
                {{ attribute }}
                {% endfor %}
                {% endif %}
            }
            {% endif %}
            {% if field.ann %}
            index {
                hnsw {
                    max-links-per-node: {{ field.ann.max_links_per_node }}
                    neighbors-to-explore-at-insert: {{ field.ann.neighbors_to_explore_at_insert }}
                }
            }
            {% endif %}
        }
        {% endfor %}
    }
{% for key, value in fieldsets.items() %}
    fieldset {{ key }} {
        fields: {{ value.fields_to_text }}
    }
{% endfor %}
{% if models %}
{% for model in models %}
    onnx-model {{ model.model_name }} {
        file: {{ model.file_path }}
        {% for key_input, value_input in model.inputs.items() %}
        input {{ key_input }}: {{ value_input }}
        {% endfor %}
        {% for key_output, value_output in model.outputs.items() %}
        output {{ key_output }}: {{ value_output }}
        {% endfor %}
    }
{% endfor %}
{% endif %}
{% for key, value in rank_profiles.items() %}
    rank-profile {{ key }}{% if value.inherits %} inherits {{ value.inherits }}{% endif %} {
        {% if value.constants %}
        constants {
        {% for constant_name, constant_value in value.constants.items() %}
            {{ constant_name }}: {{ constant_value }}
        {% endfor %}
        }
        {% endif %}
        {% if value.functions %}
        {% for function in value.functions %}
        function {{ function.name }}({{ function.args_to_text }}) {
            expression {
                {{ function.expression | indent( width=16, first=False) }}
            }
        }
        {% endfor %}
        {% endif %}
        {% if value.first_phase %}
        first-phase {
            expression: {{ value.first_phase }}
        }
        {% endif %}
        {% if value.second_phase %}
        second-phase {
            rerank-count: {{ value.second_phase.rerank_count }}
            expression: {{ value.second_phase.expression }}
        }
        {% endif %}
        {% if value.summary_features %}
        summary-features {
        {% for feature in value.summary_features %}
            {{ feature }}
        {% endfor %}
        }
        {% endif %}
    }
{% endfor %}
}