pgvector 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/LICENSE.txt +1 -1
- data/README.md +3 -5
- data/lib/pgvector/pg.rb +11 -0
- data/lib/pgvector/version.rb +1 -1
- data/lib/pgvector.rb +4 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0729ce3ec22ea08be365fc6c7a5c5e0b038860d5c9a57ccd2554d9d8b57a3f2
|
4
|
+
data.tar.gz: c36eabc18ca6db3dd47204df3c48b58f7ac635e230bb9039269506d7d8afa834
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff4dc7d6a7a26b1ff3502d2305b62fc25fff38f3bf314261dcb6aa0f40cc520963cfd9562af03b11678cad7819aef9951b480a61e138ae2ae02459ed668a5298
|
7
|
+
data.tar.gz: 6aa39019d5566f83331f3c95bb6404b065b7f7a29be62e84be2f2b6ea58bc27d20002543d93dfec7a17256c970e32b9676e2d319d07758cf49fc31b89d3d4d7b
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -25,8 +25,6 @@ And follow the instructions for your database library:
|
|
25
25
|
Register the vector type with your connection
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
require "pgvector/pg"
|
29
|
-
|
30
28
|
registry = PG::BasicTypeRegistry.new.define_default_types
|
31
29
|
Pgvector::PG.register_vector(registry)
|
32
30
|
conn.type_map_for_results = PG::BasicTypeMapForResults.new(conn, registry: registry)
|
@@ -35,14 +33,14 @@ conn.type_map_for_results = PG::BasicTypeMapForResults.new(conn, registry: regis
|
|
35
33
|
Insert a vector
|
36
34
|
|
37
35
|
```ruby
|
38
|
-
|
39
|
-
conn.exec_params("INSERT INTO items (
|
36
|
+
embedding = [1, 2, 3]
|
37
|
+
conn.exec_params("INSERT INTO items (embedding) VALUES ($1)", [embedding])
|
40
38
|
```
|
41
39
|
|
42
40
|
Get the nearest neighbors to a vector
|
43
41
|
|
44
42
|
```ruby
|
45
|
-
conn.exec_params("SELECT * FROM items ORDER BY
|
43
|
+
conn.exec_params("SELECT * FROM items ORDER BY embedding <-> $1 LIMIT 5", [embedding]).to_a
|
46
44
|
```
|
47
45
|
|
48
46
|
## History
|
data/lib/pgvector/pg.rb
CHANGED
@@ -4,6 +4,17 @@ module Pgvector
|
|
4
4
|
module PG
|
5
5
|
def self.register_vector(registry)
|
6
6
|
registry.register_type(0, "vector", nil, TextDecoder::Vector)
|
7
|
+
registry.register_type(1, "vector", nil, BinaryDecoder::Vector)
|
8
|
+
end
|
9
|
+
|
10
|
+
module BinaryDecoder
|
11
|
+
class Vector < ::PG::SimpleDecoder
|
12
|
+
def decode(string, tuple = nil, field = nil)
|
13
|
+
dim, unused = string[0, 4].unpack("nn")
|
14
|
+
raise "expected unused to be 0" if unused != 0
|
15
|
+
string[4..-1].unpack("g#{dim}")
|
16
|
+
end
|
17
|
+
end
|
7
18
|
end
|
8
19
|
|
9
20
|
module TextDecoder
|
data/lib/pgvector/version.rb
CHANGED
data/lib/pgvector.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: andrew@ankane.org
|
@@ -34,14 +34,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
34
|
requirements:
|
35
35
|
- - ">="
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
37
|
+
version: '3'
|
38
38
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
43
|
requirements: []
|
44
|
-
rubygems_version: 3.
|
44
|
+
rubygems_version: 3.4.10
|
45
45
|
signing_key:
|
46
46
|
specification_version: 4
|
47
47
|
summary: pgvector support for Ruby
|