Skip to content

Commit

Permalink
Added cast method for vector and halfvec
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed May 3, 2024
1 parent 052204e commit 5f0720b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/neighbor/type/halfvec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ def type
:halfvec
end

def cast(value)
if value.is_a?(Array)
"[#{value.join(",")}]"
else
super
end
end

def deserialize(value)
value[1..-1].split(",").map(&:to_f) unless value.nil?
end
Expand Down
8 changes: 8 additions & 0 deletions lib/neighbor/type/vector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ def type
:vector
end

def cast(value)
if value.is_a?(Array)
"[#{value.join(",")}]"
else
super
end
end

def deserialize(value)
value[1..-1].split(",").map(&:to_f) unless value.nil?
end
Expand Down

0 comments on commit 5f0720b

Please sign in to comment.