pgvector 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/LICENSE.txt +1 -1
- data/README.md +62 -5
- data/lib/pgvector/vector.rb +1 -1
- data/lib/pgvector/version.rb +1 -1
- data/lib/sequel/plugins/pgvector.rb +7 -4
- metadata +3 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7238af114feedc000b706855f9af446a583455a94771ece1e90c3e3082e63c44
|
|
4
|
+
data.tar.gz: f926141da347dc8bc1f3663e271cf3efa6b73b7c84c11e17db92f0d32af1a47c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6351a9f10f989fb92e8b5f5edea1d66dcf5110b65b748fef654faa9bfe189af64a095dd263be03af8513f552063b828730bbc09b3545f3ccf25bc7b3aef9f47a
|
|
7
|
+
data.tar.gz: 86d146518d40c9af209e9a671db10c024df4c256271de7062c4de657404508d2c0aef599cb5a9a29c6b0190f40b2bedfb91dbb41c6a31bb40b0e0b7242d4957b
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -23,11 +23,17 @@ And follow the instructions for your database library:
|
|
|
23
23
|
|
|
24
24
|
Or check out some examples:
|
|
25
25
|
|
|
26
|
-
- [Embeddings](examples/
|
|
27
|
-
- [Binary embeddings](examples/
|
|
28
|
-
- [
|
|
29
|
-
- [
|
|
30
|
-
- [
|
|
26
|
+
- [Embeddings](examples/openai/example.rb) with OpenAI
|
|
27
|
+
- [Binary embeddings](examples/cohere/example.rb) with Cohere
|
|
28
|
+
- [Sentence embeddings](examples/informers/example.rb) with Informers
|
|
29
|
+
- [Hybrid search](examples/hybrid/example.rb) with Informers (Reciprocal Rank Fusion)
|
|
30
|
+
- [Sparse search](examples/sparse/example.rb) with Transformers.rb
|
|
31
|
+
- [Morgan fingerprints](examples/rdkit/example.rb) with RDKit.rb
|
|
32
|
+
- [Topic modeling](examples/tomoto/example.rb) with tomoto.rb
|
|
33
|
+
- [User-based recommendations](examples/disco/user_recs.rb) with Disco
|
|
34
|
+
- [Item-based recommendations](examples/disco/item_recs.rb) with Disco
|
|
35
|
+
- [Horizontal scaling](examples/citus/example.rb) with Citus
|
|
36
|
+
- [Bulk loading](examples/loading/example.rb) with `COPY`
|
|
31
37
|
|
|
32
38
|
## pg
|
|
33
39
|
|
|
@@ -127,6 +133,48 @@ DB.add_index :items, :embedding, type: "hnsw", opclass: "vector_l2_ops"
|
|
|
127
133
|
|
|
128
134
|
Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance
|
|
129
135
|
|
|
136
|
+
## Reference
|
|
137
|
+
|
|
138
|
+
### Sparse Vectors
|
|
139
|
+
|
|
140
|
+
Create a sparse vector from an array
|
|
141
|
+
|
|
142
|
+
```ruby
|
|
143
|
+
vec = Pgvector::SparseVector.new([1, 0, 2, 0, 3, 0])
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Or a hash of non-zero elements
|
|
147
|
+
|
|
148
|
+
```ruby
|
|
149
|
+
vec = Pgvector::SparseVector.new({0 => 1, 2 => 2, 4 => 3}, 6)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Note: Indices start at 0
|
|
153
|
+
|
|
154
|
+
Get the number of dimensions
|
|
155
|
+
|
|
156
|
+
```ruby
|
|
157
|
+
dim = vec.dimensions
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Get the indices of non-zero elements
|
|
161
|
+
|
|
162
|
+
```ruby
|
|
163
|
+
indices = vec.indices
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Get the values of non-zero elements
|
|
167
|
+
|
|
168
|
+
```ruby
|
|
169
|
+
values = vec.values
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Get an array
|
|
173
|
+
|
|
174
|
+
```ruby
|
|
175
|
+
arr = vec.to_a
|
|
176
|
+
```
|
|
177
|
+
|
|
130
178
|
## History
|
|
131
179
|
|
|
132
180
|
View the [changelog](https://github.com/pgvector/pgvector-ruby/blob/master/CHANGELOG.md)
|
|
@@ -149,3 +197,12 @@ createdb pgvector_ruby_test
|
|
|
149
197
|
bundle install
|
|
150
198
|
bundle exec rake test
|
|
151
199
|
```
|
|
200
|
+
|
|
201
|
+
To run an example:
|
|
202
|
+
|
|
203
|
+
```sh
|
|
204
|
+
cd examples/loading
|
|
205
|
+
bundle install
|
|
206
|
+
createdb pgvector_example
|
|
207
|
+
bundle exec ruby example.rb
|
|
208
|
+
```
|
data/lib/pgvector/vector.rb
CHANGED
|
@@ -30,7 +30,7 @@ module Pgvector
|
|
|
30
30
|
|
|
31
31
|
def to_binary
|
|
32
32
|
if numo?(@data)
|
|
33
|
-
[@data.shape[0], 0].pack("s>s>") + @data.to_network.to_binary
|
|
33
|
+
[@data.shape[0], 0].pack("s>s>") + @data.to_network.to_binary.force_encoding(Encoding::BINARY)
|
|
34
34
|
else
|
|
35
35
|
buffer = [@data.size, 0].pack("s>s>")
|
|
36
36
|
@data.pack("g*", buffer: buffer)
|
data/lib/pgvector/version.rb
CHANGED
|
@@ -10,6 +10,7 @@ module Sequel
|
|
|
10
10
|
|
|
11
11
|
module DatasetMethods
|
|
12
12
|
def nearest_neighbors(column, value, distance:)
|
|
13
|
+
return extension(:null_dataset).nullify if value.nil?
|
|
13
14
|
value = ::Pgvector.encode(value) unless value.is_a?(String)
|
|
14
15
|
quoted_column = quote_identifier(column)
|
|
15
16
|
distance = distance.to_s
|
|
@@ -67,7 +68,7 @@ module Sequel
|
|
|
67
68
|
end
|
|
68
69
|
|
|
69
70
|
def []=(k, v)
|
|
70
|
-
if self.class.vector_columns.key?(k.to_sym) && !v.is_a?(String)
|
|
71
|
+
if self.class.vector_columns.key?(k.to_sym) && !v.is_a?(String) && !v.nil?
|
|
71
72
|
super(k, ::Pgvector.encode(v))
|
|
72
73
|
else
|
|
73
74
|
super
|
|
@@ -75,10 +76,12 @@ module Sequel
|
|
|
75
76
|
end
|
|
76
77
|
|
|
77
78
|
def [](k)
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
v = super
|
|
80
|
+
if self.class.vector_columns.key?(k.to_sym) && !v.nil?
|
|
81
|
+
# to_s needed for JRuby
|
|
82
|
+
::Pgvector.decode(v.to_s)
|
|
80
83
|
else
|
|
81
|
-
|
|
84
|
+
v
|
|
82
85
|
end
|
|
83
86
|
end
|
|
84
87
|
end
|
metadata
CHANGED
|
@@ -1,16 +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.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Kane
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
|
-
description:
|
|
14
12
|
email: andrew@ankane.org
|
|
15
13
|
executables: []
|
|
16
14
|
extensions: []
|
|
@@ -32,7 +30,6 @@ homepage: https://github.com/pgvector/pgvector-ruby
|
|
|
32
30
|
licenses:
|
|
33
31
|
- MIT
|
|
34
32
|
metadata: {}
|
|
35
|
-
post_install_message:
|
|
36
33
|
rdoc_options: []
|
|
37
34
|
require_paths:
|
|
38
35
|
- lib
|
|
@@ -47,8 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
47
44
|
- !ruby/object:Gem::Version
|
|
48
45
|
version: '0'
|
|
49
46
|
requirements: []
|
|
50
|
-
rubygems_version:
|
|
51
|
-
signing_key:
|
|
47
|
+
rubygems_version: 4.0.3
|
|
52
48
|
specification_version: 4
|
|
53
49
|
summary: pgvector support for Ruby
|
|
54
50
|
test_files: []
|