neighbor 0.6.0 → 1.0.0
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 +13 -11
- data/lib/neighbor/model.rb +2 -10
- data/lib/neighbor/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5caf112992a87ac93ef7d05094b9d5beb71470fef6d5dc07da8f4ba74787c381
|
|
4
|
+
data.tar.gz: 85d47b002533704a0098e41fb2e752405ea8ae50ca3cdb7d5984e0cd93016ab0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: af55fbcbe28352582379e84b0e831aae677411cf4a45432cd9a1caff7e33857d38362c6bc484a479e9c4e99f634cb094efa4ea10e02e789b4cbd552c72578b6c
|
|
7
|
+
data.tar.gz: b896e3edda9fc58a7e8aeb8aa71cf409ae5d0f8b30a785642e8380b071a0bff3e6504bc5123711405504ab7f54fb4ac856a2a26f5088bcd8bc4c963b2f4cab10
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -9,6 +9,8 @@ Supports:
|
|
|
9
9
|
- MySQL 9 (searching requires HeatWave) - experimental
|
|
10
10
|
- SQLite (sqlite-vec) - experimental
|
|
11
11
|
|
|
12
|
+
Also available for [Redis](https://github.com/ankane/neighbor-redis) and [S3 Vectors](https://github.com/ankane/neighbor-s3)
|
|
13
|
+
|
|
12
14
|
[](https://github.com/ankane/neighbor/actions)
|
|
13
15
|
|
|
14
16
|
## Installation
|
|
@@ -56,7 +58,7 @@ rails generate neighbor:sqlite
|
|
|
56
58
|
Create a migration
|
|
57
59
|
|
|
58
60
|
```ruby
|
|
59
|
-
class AddEmbeddingToItems < ActiveRecord::Migration[8.
|
|
61
|
+
class AddEmbeddingToItems < ActiveRecord::Migration[8.1]
|
|
60
62
|
def change
|
|
61
63
|
# cube
|
|
62
64
|
add_column :items, :embedding, :cube
|
|
@@ -174,7 +176,7 @@ The `sparsevec` type can have up to 16,000 non-zero elements, and sparse vectors
|
|
|
174
176
|
Add an approximate index to speed up queries. Create a migration with:
|
|
175
177
|
|
|
176
178
|
```ruby
|
|
177
|
-
class AddIndexToItemsEmbedding < ActiveRecord::Migration[8.
|
|
179
|
+
class AddIndexToItemsEmbedding < ActiveRecord::Migration[8.1]
|
|
178
180
|
def change
|
|
179
181
|
add_index :items, :embedding, using: :hnsw, opclass: :vector_l2_ops
|
|
180
182
|
# or
|
|
@@ -202,7 +204,7 @@ Item.connection.execute("SET ivfflat.probes = 3")
|
|
|
202
204
|
Use the `halfvec` type to store half-precision vectors
|
|
203
205
|
|
|
204
206
|
```ruby
|
|
205
|
-
class AddEmbeddingToItems < ActiveRecord::Migration[8.
|
|
207
|
+
class AddEmbeddingToItems < ActiveRecord::Migration[8.1]
|
|
206
208
|
def change
|
|
207
209
|
add_column :items, :embedding, :halfvec, limit: 3 # dimensions
|
|
208
210
|
end
|
|
@@ -214,7 +216,7 @@ end
|
|
|
214
216
|
Index vectors at half precision for smaller indexes
|
|
215
217
|
|
|
216
218
|
```ruby
|
|
217
|
-
class AddIndexToItemsEmbedding < ActiveRecord::Migration[8.
|
|
219
|
+
class AddIndexToItemsEmbedding < ActiveRecord::Migration[8.1]
|
|
218
220
|
def change
|
|
219
221
|
add_index :items, "(embedding::halfvec(3)) halfvec_l2_ops", using: :hnsw
|
|
220
222
|
end
|
|
@@ -232,7 +234,7 @@ Item.nearest_neighbors(:embedding, [0.9, 1.3, 1.1], distance: "euclidean", preci
|
|
|
232
234
|
Use the `bit` type to store binary vectors
|
|
233
235
|
|
|
234
236
|
```ruby
|
|
235
|
-
class AddEmbeddingToItems < ActiveRecord::Migration[8.
|
|
237
|
+
class AddEmbeddingToItems < ActiveRecord::Migration[8.1]
|
|
236
238
|
def change
|
|
237
239
|
add_column :items, :embedding, :bit, limit: 3 # dimensions
|
|
238
240
|
end
|
|
@@ -250,7 +252,7 @@ Item.nearest_neighbors(:embedding, "101", distance: "hamming").first(5)
|
|
|
250
252
|
Use expression indexing for binary quantization
|
|
251
253
|
|
|
252
254
|
```ruby
|
|
253
|
-
class AddIndexToItemsEmbedding < ActiveRecord::Migration[8.
|
|
255
|
+
class AddIndexToItemsEmbedding < ActiveRecord::Migration[8.1]
|
|
254
256
|
def change
|
|
255
257
|
add_index :items, "(binary_quantize(embedding)::bit(3)) bit_hamming_ops", using: :hnsw
|
|
256
258
|
end
|
|
@@ -262,7 +264,7 @@ end
|
|
|
262
264
|
Use the `sparsevec` type to store sparse vectors
|
|
263
265
|
|
|
264
266
|
```ruby
|
|
265
|
-
class AddEmbeddingToItems < ActiveRecord::Migration[8.
|
|
267
|
+
class AddEmbeddingToItems < ActiveRecord::Migration[8.1]
|
|
266
268
|
def change
|
|
267
269
|
add_column :items, :embedding, :sparsevec, limit: 3 # dimensions
|
|
268
270
|
end
|
|
@@ -291,7 +293,7 @@ Supported values are:
|
|
|
291
293
|
Vector columns must use `null: false` to add a vector index
|
|
292
294
|
|
|
293
295
|
```ruby
|
|
294
|
-
class CreateItems < ActiveRecord::Migration[8.
|
|
296
|
+
class CreateItems < ActiveRecord::Migration[8.1]
|
|
295
297
|
def change
|
|
296
298
|
create_table :items do |t|
|
|
297
299
|
t.vector :embedding, limit: 3, null: false
|
|
@@ -306,7 +308,7 @@ end
|
|
|
306
308
|
Use the `bigint` type to store binary vectors
|
|
307
309
|
|
|
308
310
|
```ruby
|
|
309
|
-
class AddEmbeddingToItems < ActiveRecord::Migration[8.
|
|
311
|
+
class AddEmbeddingToItems < ActiveRecord::Migration[8.1]
|
|
310
312
|
def change
|
|
311
313
|
add_column :items, :embedding, :bigint
|
|
312
314
|
end
|
|
@@ -338,7 +340,7 @@ Note: The `DISTANCE()` function is [only available on HeatWave](https://dev.mysq
|
|
|
338
340
|
Use the `binary` type to store binary vectors
|
|
339
341
|
|
|
340
342
|
```ruby
|
|
341
|
-
class AddEmbeddingToItems < ActiveRecord::Migration[8.
|
|
343
|
+
class AddEmbeddingToItems < ActiveRecord::Migration[8.1]
|
|
342
344
|
def change
|
|
343
345
|
add_column :items, :embedding, :binary
|
|
344
346
|
end
|
|
@@ -377,7 +379,7 @@ end
|
|
|
377
379
|
You can also use [virtual tables](https://alexgarcia.xyz/sqlite-vec/features/knn.html)
|
|
378
380
|
|
|
379
381
|
```ruby
|
|
380
|
-
class AddEmbeddingToItems < ActiveRecord::Migration[8.
|
|
382
|
+
class AddEmbeddingToItems < ActiveRecord::Migration[8.1]
|
|
381
383
|
def change
|
|
382
384
|
# Rails 8+
|
|
383
385
|
create_virtual_table :items, :vec0, [
|
data/lib/neighbor/model.rb
CHANGED
|
@@ -27,16 +27,8 @@ module Neighbor
|
|
|
27
27
|
@neighbor_attributes[attribute_name] = {dimensions: dimensions, normalize: normalize, type: type&.to_sym}
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Neighbor::Attribute.new(cast_type: cast_type, model: self, type: type, attribute_name: name)
|
|
33
|
-
end
|
|
34
|
-
else
|
|
35
|
-
attribute_names.each do |attribute_name|
|
|
36
|
-
attribute attribute_name do |cast_type|
|
|
37
|
-
Neighbor::Attribute.new(cast_type: cast_type, model: self, type: type, attribute_name: attribute_name)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
30
|
+
decorate_attributes(attribute_names) do |name, cast_type|
|
|
31
|
+
Neighbor::Attribute.new(cast_type: cast_type, model: self, type: type, attribute_name: name)
|
|
40
32
|
end
|
|
41
33
|
|
|
42
34
|
if normalize
|
data/lib/neighbor/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: neighbor
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Kane
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '7.
|
|
18
|
+
version: '7.2'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '7.
|
|
25
|
+
version: '7.2'
|
|
26
26
|
email: andrew@ankane.org
|
|
27
27
|
executables: []
|
|
28
28
|
extensions: []
|
|
@@ -67,14 +67,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
67
67
|
requirements:
|
|
68
68
|
- - ">="
|
|
69
69
|
- !ruby/object:Gem::Version
|
|
70
|
-
version: '3.
|
|
70
|
+
version: '3.3'
|
|
71
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
|
73
73
|
- - ">="
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
75
|
version: '0'
|
|
76
76
|
requirements: []
|
|
77
|
-
rubygems_version:
|
|
77
|
+
rubygems_version: 4.0.3
|
|
78
78
|
specification_version: 4
|
|
79
79
|
summary: Nearest neighbor search for Rails
|
|
80
80
|
test_files: []
|