# Complete grouped configuration. Paths are relative to this file.
# Active profile: folder OKF, encrypted SQLite, lexical retrieval, read-only TLS/MCP.
# Commented blocks are alternatives or opt-ins. See ../docs/configuration.md.

source:
  format: open_knowledge_format
  path: ../examples/bundle
  strict_metadata: true
  # For authoritative OKF in SQL, replace path with one backend block.
  # backend:
  #   type: postgres
  #   connection:
  #     host: okf-db.example.net
  #     port: 5432
  #     database: authoring
  #     user: okf_reader
  #     password: {env: KNOWLEDGE_OKF_PG_PASSWORD}
  #     ca_file: ./trust/okf-postgres-ca.pem
  #   watch_channel: okf_updated
  #   mappings:
  #     - {schema: publishing, table: pages, path_column: path, content_column: markdown}
  #     - {schema: publishing, table: assets, path_column: path, content_column: payload, content_type: bytes, prefix: assets}
  #   limits: {timeout_secs: 30, max_snapshot_bytes: 67108864}
  # backend:
  #   type: sqlite
  #   path: ./authoring.sqlite
  #   mappings: [{table: pages, path_column: path, content_column: markdown}]
  #   limits: {timeout_secs: 30, max_snapshot_bytes: 67108864}

storage:
  database: ../.knowledge-secure/reference/index.sqlite
  encryption_key: {file: ../.knowledge-secure/secrets/database.key}
  # Shared PostgreSQL index, independent of the source backend above.
  # Remove supplemental sources and keep urls, consolidation and federation off.
  # For the PG reader set server.watch=false and disable writes, tasks and Events.
  # Use separate migration, worker and reader configs with the same bundle recipe.
  # postgres:
  #   bundle: notebook
  #   connection:
  #     host: index-db.example.net
  #     port: 5432
  #     database: knowledge
  #     user: knowledge_reader
  #     password: {env: KNOWLEDGE_INDEX_PG_PASSWORD}
  #     ca_file: ./trust/index-postgres-ca.pem
  #   max_projection_bytes: 67108864
  #   provider_quota: {group: embeddings, max_running: 2}
  #   native_vector: {dimensions: 768, ef_search: 100}

# Supplemental inputs for SQLite. In place of {}, add any of the entries below.
sources: {}
# sources:
#   lab:
#     input:
#       type: sqlite
#       path: ./sources/lab.sqlite
#       tables:
#         - {table: devices, id_column: id, title_column: title, text_columns: [notes], metadata_columns: [team]}
#         - table: manuals
#           id_column: id
#           text_columns: [content]
#           links: [{column: device_id, target_table: devices, predicate: documents}]
#     limits: {poll_interval_secs: 15, timeout_secs: 30, max_records: 1000, max_snapshot_bytes: 67108864}
#   references:
#     input: {type: manifest, path: ./sources/manifest.yml, local_root: ./sources/assets}
#     limits: {poll_interval_secs: 30}
#   archive:
#     input:
#       type: s3
#       endpoint: https://objects.example.net
#       region: us-east-1
#       bucket: knowledge-archive
#       prefix: approved/
#       access_key_env: KNOWLEDGE_S3_ACCESS_KEY
#       secret_key_env: KNOWLEDGE_S3_SECRET_KEY
#       session_token_env: null
#       allow_loopback_http: false
#     limits: {poll_interval_secs: 60}

models:
  enrich: false
  # Choose one text encoder: embedding.gguf, embedding.http, or apple.embedding.
  # embedding:
  #   document_prefix: "title: none | text: "
  #   query_prefix: "task: search result | query: "
  #   shared_space: null # Assert only for known compatible encoders.
  #   gguf:
  #     path: ../models/embeddinggemma-2-Q8_0.gguf
  #     revision: sha256:2188ac1deca4b77dffefd603c2776a9d76d9d74ec01841392982ebb840b09135
  #     context_size: 2048
  #     gpu_layers: 0 # Enable GPU only on a compatible build.
  #     threads: 4
  #     projector_path: ../models/mmproj-embeddinggemma-2-Q8_0.gguf
  #     projector_revision: sha256:0531309472a6bc6f4b146c3736eee7795ec9db1903c25490d3c937490cef6dd8
  #   http: {url: http://127.0.0.1:8080/v1/embeddings, model: my-encoder, revision: v1, protocol: openai, api_key_env: null}
  # media_embedding: {url: http://127.0.0.1:8081/embed-media, model: paired-media, revision: v1, format: base64, api_key_env: null}
  # generation:
  #   path: ../models/qwen2.5-1.5b-instruct-q4_k_m.gguf
  #   revision: sha256:6a1a2eb6d15622bf3c96857206351ba97e1af16c30d7a74ee38970e434e9407e
  #   context_size: 8192
  #   max_tokens: 384
  #   gpu_layers: 0
  #   threads: 4
  #   enrich: false
  # chat: {url: http://127.0.0.1:8080/v1/chat/completions, model: my-chat, revision: v1, protocol: openai, api_key_env: null}
  # vision: {url: http://127.0.0.1:8081/v1/chat/completions, model: my-vision, revision: v1, protocol: openai, api_key_env: null}
  # transcription: {url: http://127.0.0.1:8082/inference, protocol: whisper_cpp, revision: v1, model: null, language: en, api_key_env: null}
  # reranker: {url: http://127.0.0.1:8083/rerank, model: my-reranker, revision: v1, protocol: openai, api_key_env: null}
  # apple:
  #   helper: ../target/apple/knowledge-apple-models
  #   revision: system
  #   embedding: {language: en, revision: 1}
  #   generation: true
  #   vision: true
  #   max_response_tokens: 1024
  #   timeout_secs: 60

chunking:
  strategy: markdown # fixed | recursive | sentence | markdown
  max_chars: 1800
  max_tokens: null
  overlap_chars: 180
  rules:
    - prefix: procedures
      chunks: {strategy: sentence, max_chars: 800, max_tokens: 256, overlap_chars: 80}

retrieval:
  vector_backend: float32
  lexical_weight: 1.0
  vector_weight: 1.0
  rrf_k: 60
  candidates: 40
  rerank: none # none | coverage | mmr | http
  rerank_candidates: 20
  mmr_lambda: 0.7
  graph_predicates: []
  graph_outgoing_only: false
  graph_context_chunks: 10
  max_snapshot_chunks: 50000
  max_snapshot_bytes: 134217728

# SQLite compatibility-search TurboQuant. Requires an embedding model.
# compression: {bits: 3, seed: 1263423319, exact_rerank: true}

video:
  enabled: false
  ffmpeg: ffmpeg
  ffprobe: ffprobe
  frame_interval_ms: 10000
  audio_segment_secs: 10
  max_frames: 60
  max_audio_segments: 60
  max_duration_secs: 600
  max_output_bytes: 67108864
  process_timeout_secs: 60
  frame_max_edge: 512
  extract_audio: true

pdf:
  enabled: false
  pdftotext: pdftotext
  pdfinfo: pdfinfo
  pdftoppm: pdftoppm
  max_pages: 100
  render_pages: false
  render_max_edge: 768
  max_output_bytes: 67108864
  process_timeout_secs: 60

urls:
  enabled: false
  allowed_origins: []
  allow_loopback_http: false
  max_resources_per_document: 16
  max_resource_bytes: 16777216
  max_total_bytes: 67108864
  refresh_secs: 3600
  timeout_secs: 30
  extra_ca_file: null

indexing:
  timeout_secs: 120
  scan_interval_ms: 2000
  debounce_ms: 300
  change_batching: {min_scan_interval_ms: 1000, quiet_ms: 1500, max_delay_ms: 30000}
  lease_secs: 180
  max_attempts: 5
  retry_base_secs: 2
  embedding_batch_size: 16
  max_file_bytes: 67108864
  max_scan_files: 10000
  max_scan_entries: 50000
  max_scan_bytes: 536870912
  pipeline_revision: "1"
  resources:
    cpu_threads: 2
    max_gpu_layers: 0
    max_concurrent_jobs: 1
    max_concurrent_source_polls: 2
    max_embedding_batch_size: 8
    duty_cycle_percent: 50
    min_idle_ms: 100
    max_jobs_per_minute: null
    max_rss_mb: null

consolidation:
  enabled: false
  strategy: extractive # model uses the selected analysis backend.
  interval_secs: 600
  max_sources_per_run: 4
  max_evidence_per_source: 4
  max_input_bytes: 16384
  max_output_bytes: 16384
  max_claims: 8
  timeout_secs: 120
  max_attempts: 3
  proposal_prefix: derived
  source_prefixes: [procedures]
  recipe_revision: "1"
  model: {http: null, gguf: null} # Endpoint or generation block as above.

security:
  network:
    allow_remote_https: false
    allow_loopback_http: false # Set true for the commented local HTTP model examples.
    extra_ca_file: null

server:
  listen: 127.0.0.1:8443
  transport: {max_connections: 128, tls_handshake_timeout_secs: 10, header_timeout_secs: 10, shutdown_grace_secs: 5}
  certificate: ../.knowledge-secure/secrets/server.pem
  private_key: ../.knowledge-secure/secrets/server-key.pem
  read_token: {file: ../.knowledge-secure/secrets/read.token}
  admin_token: null
  require_encryption: true
  allow_insecure_loopback: false
  allowed_hosts: [localhost, 127.0.0.1, "[::1]"]
  allowed_origins: []
  allow_source_writes: false
  max_upload_bytes: 33554432
  max_body_bytes: 65536
  max_query_chars: 8000
  max_context_chars: 16000
  max_parallel_requests: 2
  requests_per_minute: 120
  request_timeout_secs: 60
  watch: true
  poll: false
  principals: []
  # principals: [{name: procedures-reader, token: {env: KNOWLEDGE_PROCEDURES_TOKEN}, capabilities: [read], prefixes: [procedures]}]
  mtls: null
  # mtls:
  #   client_ca: ./trust/clients.pem
  #   required: true
  #   principals: [{principal: peer-reader, certificate_sha256: REPLACE_WITH_BASE64URL_SHA256}]
  oauth: {resource: "", jwks_cache_secs: 0, issuers: [], login: {}}
  # oauth:
  #   resource: https://knowledge.example.net
  #   jwks_cache_secs: 300
  #   issuers:
  #     - issuer: https://idp.example.net/openapi
  #       audience: https://knowledge.example.net
  #       jwks_url: https://idp.example.net/openapi/keys
  #       algorithms: [RS256, ES256, EdDSA]
  #       extra_ca_file: null
  #       allow_insecure_loopback: false
  #       # introspection: {url: https://idp.example.net/introspect, client_id: knowledge, client_secret_env: KNOWLEDGE_INTROSPECTION_SECRET}
  #       rules:
  #         - {principal: oauth-reader, client_id: knowledge-app, subject: null, scopes: ["knowledge:read"], prefixes: [procedures], capabilities: [read], proof: none}
  #   login: {} # Named outbound OIDC profiles are shown in ../docs/federation-security.md.
  mcp:
    http:
      enabled: true
      oauth_resource: null # Add an allowed HTTPS /mcp URL and matching issuer audience.
      oauth_only: false
      server_card: null # {name: net.example/knowledge, url: https://knowledge.example.net/mcp, description: OKF evidence}
    stdio: {prefixes: [procedures, references]}
    features: {skills: true, apps: true, authoring: false, tasks: false, subscriptions: true, context_tasks: false}
    tools: {allow: null} # Optional list of short tool names, e.g. [retrieve, context, select, evidence].
    limits:
      payload_bytes: 262144
      subscription_streams: 16
      subscription_lifetime_secs: 300
      subscription_poll_ms: 2000
      task_ttl_secs: 86400
      task_poll_ms: 1000
      context_task_capacity: 32
      context_tasks_per_principal: 8
    interaction: {clarify_context_query: false, state_key: null, ttl_secs: 180}
    skill_catalog: {entries: []} # Entries take directory, files and required_prefixes.
    events:
      enabled: false
      cursor_key: null
      poll: {max_events: 32, max_scan_rows: 512, max_replay_age_secs: 86400, interval_ms: 2000}
      push: {enabled: false, max_streams: 4, lifetime_secs: 300, heartbeat_secs: 15}
      webhooks:
        max_subscriptions: 16
        ttl_secs: 300
        timeout_secs: 5
        max_attempts: 3
        signing: null
        # signing: {key_id: events-v1, seed: {env: KNOWLEDGE_WEBHOOK_SEED}, previous_keys: []}
        targets: []
        # targets: [{url: https://receiver.example.net/events, address: 192.0.2.10, principals: [oauth-reader], ca_file: null}]

federation:
  enabled: false
  signing_key: null
  publisher_id: null
  collection_lineage: null
  shares: []
  grants: []
  peers: []
  mounts: []
  query: {max_peers: 4, concurrency: 2, peer_timeout_ms: 700, deadline_ms: 1500, candidates_per_peer: 16, max_candidates: 64, max_response_bytes: 2097152, max_inflight_bytes: 8388608}
  sync: {interval_secs: 30, batch_size: 256, max_staged_bytes: 33554432, max_blob_bytes: 33554432, max_index_bytes: 67108864, bytes_per_second: 4194304, timeout_secs: 120}
  consolidation: {enabled: false, workspaces: []}
  # See federation-owner.yml and federation-consumer.yml for enrolled entries.
