pgvector 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07a80636c13841d2fa97f8b740feb095c1c2f94fa3691b374d1472bba918bddf
4
- data.tar.gz: 50c9e67781fbbe23fa3dbe2f87790025f18d3686e412b46f62d1cb0d2995ecb3
3
+ metadata.gz: 3d3ef6a53417383ff7f8a2a514df78513dfe9029e524f0f624df8828fb99dba0
4
+ data.tar.gz: f326a21d3942079cdadc22d9a61367e7a6651ae37c5eb07a3955182f9f569ad0
5
5
  SHA512:
6
- metadata.gz: f0aa5b733e1bc4022c2052be6b04aa0656bf306f588baf2907827674aeadc7dc52507895043049246634999dea37de629c19a164bd289fbd979eb628aaab0c33
7
- data.tar.gz: f52e2e9c1c074c4f809fe78d6926bcb630694d79199e288ebb33d136a05191c4b2fff6038f8d7fc56d4291f949caa1b536d942aa7d0912be2daccf5a7ee23f83
6
+ metadata.gz: fa4d6519685d179e3d5712cbcf1e6989ca4f98e5b0902f5061eca2be55451162f199fcc75f19841dbd8ada8c18de69ac6fa39cad545d4b5a6c542e9cdd0109ea
7
+ data.tar.gz: fd71245492b2ff8a06a0af60dbd12e57e44025f2662d4ea77eb7176aaaa4c4cb3b39c1e159edce92944da5b54fddbb19d1b504acd76a12c4efdb9a0fb6e797da
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.3.1 (2024-07-10)
2
+
3
+ - Added support for `bit` type to pg
4
+ - Added extension for Sequel
5
+
1
6
  ## 0.3.0 (2024-06-25)
2
7
 
3
8
  - Added support for `halfvec` and `sparsevec` types
@@ -0,0 +1,28 @@
1
+ module Pgvector
2
+ class Bit
3
+ def initialize(data)
4
+ if data.is_a?(Array)
5
+ @data = data.map { |v| v ? "1" : "0" }.join
6
+ else
7
+ @data = data.to_str
8
+ end
9
+ end
10
+
11
+ def self.from_text(string)
12
+ Bit.new(string)
13
+ end
14
+
15
+ def self.from_binary(string)
16
+ length = string[..3].unpack1("l>")
17
+ Bit.new(string[4..].unpack("B*").join[...length])
18
+ end
19
+
20
+ def to_s
21
+ @data
22
+ end
23
+
24
+ def to_a
25
+ @data.each_char.map { |v| v != "0" }
26
+ end
27
+ end
28
+ end
data/lib/pgvector/pg.rb CHANGED
@@ -9,6 +9,9 @@ module Pgvector
9
9
  # no binary decoder for halfvec since unpack does not have directive for half-precision
10
10
  registry.register_type(0, "halfvec", nil, TextDecoder::Halfvec)
11
11
 
12
+ registry.register_type(0, "bit", nil, TextDecoder::Bit)
13
+ registry.register_type(1, "bit", nil, BinaryDecoder::Bit)
14
+
12
15
  registry.register_type(0, "sparsevec", nil, TextDecoder::Sparsevec)
13
16
  registry.register_type(1, "sparsevec", nil, BinaryDecoder::Sparsevec)
14
17
  end
@@ -20,6 +23,12 @@ module Pgvector
20
23
  end
21
24
  end
22
25
 
26
+ class Bit < ::PG::SimpleDecoder
27
+ def decode(string, tuple = nil, field = nil)
28
+ ::Pgvector::Bit.from_binary(string).to_s
29
+ end
30
+ end
31
+
23
32
  class Sparsevec < ::PG::SimpleDecoder
24
33
  def decode(string, tuple = nil, field = nil)
25
34
  SparseVector.from_binary(string)
@@ -40,6 +49,12 @@ module Pgvector
40
49
  end
41
50
  end
42
51
 
52
+ class Bit < ::PG::SimpleDecoder
53
+ def decode(string, tuple = nil, field = nil)
54
+ ::Pgvector::Bit.from_text(string).to_s
55
+ end
56
+ end
57
+
43
58
  class Sparsevec < ::PG::SimpleDecoder
44
59
  def decode(string, tuple = nil, field = nil)
45
60
  SparseVector.from_text(string)
@@ -1,3 +1,3 @@
1
1
  module Pgvector
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
data/lib/pgvector.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # modules
2
+ require_relative "pgvector/bit"
2
3
  require_relative "pgvector/half_vector"
3
4
  require_relative "pgvector/sparse_vector"
4
5
  require_relative "pgvector/vector"
@@ -8,7 +9,7 @@ module Pgvector
8
9
  autoload :PG, "pgvector/pg"
9
10
 
10
11
  def self.encode(data)
11
- if data.is_a?(SparseVector)
12
+ if data.is_a?(Vector) || data.is_a?(HalfVector) || data.is_a?(SparseVector)
12
13
  data.to_s
13
14
  else
14
15
  Vector.new(data).to_s
@@ -0,0 +1,5 @@
1
+ require_relative "../plugins/pgvector"
2
+
3
+ module Sequel
4
+ Dataset.register_extension(:pgvector, Plugins::Pgvector::DatasetMethods)
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgvector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-26 00:00:00.000000000 Z
11
+ date: 2024-07-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: andrew@ankane.org
@@ -20,11 +20,13 @@ files:
20
20
  - LICENSE.txt
21
21
  - README.md
22
22
  - lib/pgvector.rb
23
+ - lib/pgvector/bit.rb
23
24
  - lib/pgvector/half_vector.rb
24
25
  - lib/pgvector/pg.rb
25
26
  - lib/pgvector/sparse_vector.rb
26
27
  - lib/pgvector/vector.rb
27
28
  - lib/pgvector/version.rb
29
+ - lib/sequel/extensions/pgvector.rb
28
30
  - lib/sequel/plugins/pgvector.rb
29
31
  homepage: https://github.com/pgvector/pgvector-ruby
30
32
  licenses: