Class: Hnswlib::L2Space
- Inherits:
-
Object
- Object
- Hnswlib::L2Space
- Defined in:
- ext/hnswlib/dummy.rb
Overview
L2Space is a class that calculates squared Euclidean distance for search index. This class is used internally.
Instance Method Summary collapse
-
#distance(arr_a, arr_b) ⇒ Float
Calculate the squared Euclidean distance between items: d = sum((Ai - Bi)^2).
-
#initialize(dim) ⇒ L2Space
constructor
Create a new L2Space.
Constructor Details
#initialize(dim) ⇒ L2Space
Create a new L2Space.
23 24 25 |
# File 'ext/hnswlib/dummy.rb', line 23 def initialize(dim) @dim = dim end |
Instance Method Details
#distance(arr_a, arr_b) ⇒ Float
Calculate the squared Euclidean distance between items: d = sum((Ai - Bi)^2)
33 34 35 |
# File 'ext/hnswlib/dummy.rb', line 33 def distance(arr_a, arr_b) a.zip(b).sum { |v| (v[0] - v[1])**2 } end |