# typed: strict
module Domain::NeighborFinder
  extend T::Sig

  sig do
    type_parameters(:F)
      .params(factors: T.all(T.type_parameter(:F), Domain::Factors))
      .returns(ActiveRecord::Relation)
  end
  def self.find_neighbors(factors)
    Domain::Factors.connection.execute("SET ivfflat.max_probes = 10")
    Domain::Factors.connection.execute("SET ivfflat.probes = 10")
    factors.nearest_neighbors(:embedding, distance: "euclidean")
  end
end
