Sha256: 98e06f42b2fc6aab77a67f9e26c897ab03bd89f10c718021b996a73f21d2e98d

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Manifold
  module Services
    # Handles the loading of vector schemas from configuration files
    class VectorService
      def initialize(logger)
        @logger = logger
      end

      def load_vector_schema(vector_name)
        path = config_path(vector_name)
        config = YAML.safe_load_file(path)
        fields = transform_attributes_to_schema(config["attributes"])
        { "name" => vector_name.downcase, "type" => "RECORD", "fields" => fields }
      rescue Errno::ENOENT, Errno::EISDIR
        raise "Vector configuration not found: #{path}"
      rescue Psych::Exception => e
        raise "Invalid YAML in vector configuration #{path}: #{e.message}"
      end

      private

      def transform_attributes_to_schema(attributes)
        attributes.map do |name, type|
          {
            "name" => name,
            "type" => type.upcase,
            "mode" => "NULLABLE"
          }
        end
      end

      def config_path(vector_name)
        Pathname.pwd.join("vectors", "#{vector_name.downcase}.yml")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
manifold-cli-0.0.8 lib/manifold/services/vector_service.rb