0
     ˆÂÁÈ517ÀÇÆ     ‹      Å•M�Ú0†ïû+\z#“@¶ÚÇ%HEe±TUUõàÄ&±68‘í-Ð__CÒ]¨ ÝVˆž2N^¿žg&ò�Wñ¸7û<é£÷³»!š||7ôn|êô âY\=? è�0Â¹µÕÀr¹ô–¯ÔÌ¦�ÛE‚±Z¦Öã–czA6ïè"¹`Ü=±Ò‚+TÎ”�ÖH.B(dS0ÒŠ–5ÓkÈ´äý•ÕrQTê½Î;’”|½9%øGG·q›K¶Æ›PSbsô�2S¶e…)‘‹�FdZ*IÁÔƒ—É9F¬°þ2è�¿:Ø|³›†r-æ~Û‹F·ã¨‹éˆ-vXsWk†ÌX´(¹œKÁ�Šïkñ½ü~Ü0®5±0©–••¥z–‚CÜEMËÂTÌ±^:‚\ïªj	ÿS5XºWŒIwÚÍâÁ´.	ßX<g÷Âþ`:aZ(‹b©EjK½nj»×*1ÕíÏ%jòÓ2Ë-¦µÐAå_@=ªU.Õ.—«ÙA¢ŠÙÜxšLŸÂÝdÉ®í·ý–Ù
Þ  ¼ñ}„Žƒ««sb<ÕÞå¿Âtoy
œöuø¿p’}œä8(è|8#ŽóaF4¿ÙÎâ$�	ýsv¦«¶—5¦Mp
„Ð¿þÂo;hæ �í\!PO¯kò\     [   ˆl–Ü4ý('ÜZÔâ€vàZ¸ÓJbÑ¿�þe}¥œl�Èû�ºðK'óÊƒe÷žÉ_�uÐb&=LyZËcõa–Ãa¾”J_)â€jãmÜŠbÑ¿É ”    # Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

# What a connection embeds with, and whether replacing one with another leaves the index describing
# something else. The single rule behind both halves of the story: the warning an admin gets before a
# change, and the rebuild that follows it.
#
# Two values decide it. The **model** is what identifies the vectors - the same rule the embedding
# cache is keyed by (Service::AI::VectorDB::Embedding::Cache#digest) - so where it is served from is
# deliberately not part of this: moving 'bge-m3' from a self-hosted Ollama to Zammad AI embeds
# against the same model, and charging a full re-index for the move would be the tokens the warning
# exists to save. The **vector length** is not sent to any provider and changes nothing about the
# vectors, but it is what the index mapping is created with (`dense_vector dims:`), and no reload can
# alter that afterwards.
class Service::AI::VectorDB::Embedding::Configuration
  class << self
    # @return [Hash, NilClass] model and size, nil where the connection embeds with nothing
    def of(connection)
      return nil if connection.nil?

      for_provider(provider: connection.provider, config: connection.config)
    end

    # The configuration semantic search runs on right now.
    #
    # @return [Hash, NilClass]
    def current
      of(AI::ProviderConnection.for_embeddings)
    end

    # The same for values that are not stored yet - what a dialog submitted, which is what the
    # warning is decided on before anything is saved.
    #
    # @return [Hash, NilClass]
    def for_provider(provider:, config:)
      klass = AI::Provider.by_name(provider)
      return nil if klass.nil?

      instance = klass.new(config: normalized_config(klass, config))
      model    = instance.embedding_model
      return nil if model.blank?

      { model: model, size: instance.embedding_size }
    end

    # Whether going from one to the other leaves the index holding vectors nothing queries anymore.
    #
    # Ending up with nothing to embed with is no such change: there is nothing to rebuild from, so
    # the index is left standing rather than dropped - clearing the semantic search default turns the
    # feature off, it does not throw the vectors away.
    def changed?(before, after)
      return false if after.nil?

      before != after
    end

    # What the index was last built with, read from the hidden setting rather than from the connection
    # - the two can disagree by design (a config edited or the feature disabled since the last rebuild
    # ran). {} and nil both mean nothing ever built.
    #
    # @return [Hash, NilClass] normalized to the same shape and key types #current returns, so the two
    #   compare equal with plain `==`.
    def indexed
      value = Setting.get('vectordb_indexed_embedding_configuration')
      return nil if value.blank?

      value.symbolize_keys.slice(:model, :size)
    end

    # Only the rebuild job calls this, once the index actually holds what `configuration` describes.
    #
    # @param configuration [Hash, NilClass] the configuration the index was just built (or reloaded)
    #   with; nil/{} record that nothing is built.
    def record_indexed(configuration)
      Setting.set('vectordb_indexed_embedding_configuration', configuration.presence || {})
    end

    private

    # A provider serving a fixed model stores none