Module: Pgvector

Defined in:
lib/pgvector.rb,
lib/pgvector/pg.rb,
lib/pgvector/vector.rb,
lib/pgvector/version.rb,
lib/pgvector/half_vector.rb,
lib/pgvector/sparse_vector.rb

Defined Under Namespace

Modules: PG Classes: HalfVector, SparseVector, Vector

Constant Summary collapse

VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.decode(string) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/pgvector.rb', line 18

def self.decode(string)
  if string[0] == "["
    Vector.from_text(string).to_a
  elsif string[0] == "{"
    SparseVector.from_text(string)
  else
    string
  end
end

.encode(data) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/pgvector.rb', line 10

def self.encode(data)
  if data.is_a?(SparseVector)
    data.to_s
  else
    Vector.new(data).to_s
  end
end