Skip to content

Commit

Permalink
Fixed previous commit for Active Record < 7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Oct 7, 2024
1 parent 29684d8 commit 8a8c95a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/neighbor/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def self.neighbor_attributes

distance = distance.to_s

quoted_attribute = with_connection { |c| "#{c.quote_table_name(table_name)}.#{c.quote_column_name(attribute_name)}" }
quoted_attribute = connection_pool.with_connection { |c| "#{c.quote_table_name(table_name)}.#{c.quote_column_name(attribute_name)}" }

column_info = columns_hash[attribute_name.to_s]
column_type = column_info&.type
Expand All @@ -113,7 +113,7 @@ def self.neighbor_attributes
Neighbor::Utils.validate(vector, dimensions: dimensions, type: type || Utils.type(adapter, column_info&.type), adapter: adapter)
vector = Neighbor::Utils.normalize(vector, column_info: column_info) if normalize

query = with_connection { |c| c.quote(column_attribute.serialize(vector)) }
query = connection_pool.with_connection { |c| c.quote(column_attribute.serialize(vector)) }

if !precision.nil?
if adapter != :postgresql || column_type != :vector
Expand All @@ -124,7 +124,7 @@ def self.neighbor_attributes
when "half"
cast_dimensions = dimensions || column_info&.limit
raise ArgumentError, "Unknown dimensions" unless cast_dimensions
quoted_attribute += "::halfvec(#{with_connection { |c| c.quote(cast_dimensions.to_i) }})"
quoted_attribute += "::halfvec(#{connection_pool.with_connection { |c| c.quote(cast_dimensions.to_i) }})"
else
raise ArgumentError, "Invalid precision"
end
Expand Down

0 comments on commit 8a8c95a

Please sign in to comment.