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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/pgvector/bit.rb +28 -0
- data/lib/pgvector/pg.rb +15 -0
- data/lib/pgvector/version.rb +1 -1
- data/lib/pgvector.rb +2 -1
- data/lib/sequel/extensions/pgvector.rb +5 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d3ef6a53417383ff7f8a2a514df78513dfe9029e524f0f624df8828fb99dba0
|
4
|
+
data.tar.gz: f326a21d3942079cdadc22d9a61367e7a6651ae37c5eb07a3955182f9f569ad0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa4d6519685d179e3d5712cbcf1e6989ca4f98e5b0902f5061eca2be55451162f199fcc75f19841dbd8ada8c18de69ac6fa39cad545d4b5a6c542e9cdd0109ea
|
7
|
+
data.tar.gz: fd71245492b2ff8a06a0af60dbd12e57e44025f2662d4ea77eb7176aaaa4c4cb3b39c1e159edce92944da5b54fddbb19d1b504acd76a12c4efdb9a0fb6e797da
|
data/CHANGELOG.md
CHANGED
data/lib/pgvector/bit.rb
ADDED
@@ -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)
|
data/lib/pgvector/version.rb
CHANGED
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
|
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.
|
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-
|
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:
|