Module: IndexUtil::FragmentEmbedding
- Defined in:
- lib/index_util/fragment_embedding.rb
Class Method Summary collapse
Class Method Details
.norm(vector) ⇒ Object
17 18 19 |
# File 'lib/index_util/fragment_embedding.rb', line 17 def norm(vector) Math.sqrt(Array(vector).sum { |value| value.to_f * value.to_f }) end |
.pack(vector) ⇒ Object
9 10 11 |
# File 'lib/index_util/fragment_embedding.rb', line 9 def pack(vector) Sequel.blob(Array(vector).map(&:to_f).pack("f*")) end |
.unpack(blob) ⇒ Object
13 14 15 |
# File 'lib/index_util/fragment_embedding.rb', line 13 def unpack(blob) blob.unpack("f*") end |