# RAG System Configuration - Nickel Format
# Auto-generated by provisioning TypeDialog
# Edit via: nu provisioning/.typedialog/provisioning/platform/scripts/configure.nu rag {mode}
# Or manually edit and validate with: nickel typecheck

let rag_schema = import "../schemas/rag.ncl" in

{
  rag | rag_schema.RagConfig = {
    # RAG System Control
    {%- if rag_enabled is defined %}
    rag = {
      enabled = {{ rag_enabled | lower }},
    },
    {%- endif %}

    # Embeddings Configuration
    {%- if embeddings_provider or embeddings_model %}
    embeddings = {
      {{%- if embeddings_provider %}
      provider = "{{ embeddings_provider }}",
      {%- endif %}
      {%- if embeddings_model %}
      model = "{{ embeddings_model }}",
      {%- endif %}
      {%- if embeddings_dimension %}
      dimension = {{ embeddings_dimension }},
      {%- endif %}
      {%- if embeddings_batch_size %}
      batch_size = {{ embeddings_batch_size }},
      {%- endif %}
      {%- if embeddings_api_key %}
      api_key = "{{ embeddings_api_key }}",
      {%- endif %}
    },
    {%- endif %}

    # Vector Database Configuration
    {%- if vector_db_type or vector_db_url %}
    vector_db = {
      {%- if vector_db_type %}
      db_type = "{{ vector_db_type }}",
      {%- endif %}
      {%- if vector_db_url %}
      url = "{{ vector_db_url }}",
      {%- endif %}
      {%- if vector_db_namespace %}
      namespace = "{{ vector_db_namespace }}",
      {%- endif %}
      {%- if vector_db_database %}
      database = "{{ vector_db_database }}",
      {%- endif %}
      {%- if vector_db_hnsw_m %}
      hnsw_m = {{ vector_db_hnsw_m }},
      {%- endif %}
      {%- if vector_db_hnsw_ef_construction %}
      hnsw_ef_construction = {{ vector_db_hnsw_ef_construction }},
      {%- endif %}
    },
    {%- endif %}

    # Language Model Configuration
    {%- if llm_provider or llm_model %}
    llm = {
      {%- if llm_provider %}
      provider = "{{ llm_provider }}",
      {%- endif %}
      {%- if llm_model %}
      model = "{{ llm_model }}",
      {%- endif %}
      {%- if llm_api_key %}
      api_key = "{{ llm_api_key }}",
      {%- endif %}
      {%- if llm_api_url %}
      api_url = "{{ llm_api_url }}",
      {%- endif %}
      {%- if llm_temperature %}
      temperature = {{ llm_temperature }},
      {%- endif %}
      {%- if llm_max_tokens %}
      max_tokens = {{ llm_max_tokens }},
      {%- endif %}
    },
    {%- endif %}

    # Retrieval Configuration
    {%- if retrieval_top_k or retrieval_similarity_threshold %}
    retrieval = {
      {%- if retrieval_top_k %}
      top_k = {{ retrieval_top_k }},
      {%- endif %}
      {%- if retrieval_similarity_threshold %}
      similarity_threshold = {{ retrieval_similarity_threshold }},
      {%- endif %}
      {%- if retrieval_reranking is defined %}
      reranking = {{ retrieval_reranking | lower }},
      {%- endif %}
      {%- if retrieval_hybrid is defined %}
      hybrid = {{ retrieval_hybrid | lower }},
      {%- endif %}
      {%- if retrieval_mmr_lambda %}
      mmr_lambda = {{ retrieval_mmr_lambda }},
      {%- endif %}
    },
    {%- endif %}

    # Document Ingestion Configuration
    {%- if ingestion_auto_ingest is defined or ingestion_chunk_size %}
    ingestion = {
      {%- if ingestion_auto_ingest is defined %}
      auto_ingest = {{ ingestion_auto_ingest | lower }},
      {%- endif %}
      {%- if ingestion_watch_files is defined %}
      watch_files = {{ ingestion_watch_files | lower }},
      {%- endif %}
      {%- if ingestion_chunk_size %}
      chunk_size = {{ ingestion_chunk_size }},
      {%- endif %}
      {%- if ingestion_overlap %}
      overlap = {{ ingestion_overlap }},
      {%- endif %}
      {%- if ingestion_doc_types %}
      doc_types = [{{ ingestion_doc_types }}],
      {%- endif %}
    },
    {%- endif %}

    # Logging Configuration (optional)
    {%- if logging_level %}
    logging = {
      level = "{{ logging_level }}",
      {%- if logging_format %}
      format = "{{ logging_format }}",
      {%- endif %}
    },
    {%- endif %}

    # Monitoring Configuration (optional)
    {%- if monitoring_enabled is defined %}
    monitoring = {
      enabled = {{ monitoring_enabled | lower }},
      {%- if monitoring_metrics_interval %}
      metrics_interval = {{ monitoring_metrics_interval }},
      {%- endif %}
    },
    {%- endif %}
  },
}
