module Neighbor::Utils
def self.normalize(value, column_info:)
def self.normalize(value, column_info:) return nil if value.nil? raise Error, "Normalize not supported for type" unless [:cube, :vector, :halfvec].include?(column_info&.type) norm = Math.sqrt(value.sum { |v| v * v }) # store zero vector as all zeros # since NaN makes the distance always 0 # could also throw error norm > 0 ? value.map { |v| v / norm } : value end