neighbor 0.2.0 → 0.2.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: 9a8839eeaeeef5b3ff8deb63165791929a81f9a9c1c807dd3d094e9bf770e881
4
- data.tar.gz: 14035d37686f7035bc0e874de7933259dc0b8be9d046fca1d31867cacaf1c922
3
+ metadata.gz: 8a71d9aff5133b9551dc47cfe490d5d6a0ee63d2b77ac1d3d2f381f58aef67d6
4
+ data.tar.gz: d22cab3140b979ee0d13ddd2c99f064282e896d49c265bf9b1946dafbda7783a
5
5
  SHA512:
6
- metadata.gz: bfbf7bca1b4290abf2ec91dd5ea032dd1878ab9d7a0938dfed4e6e63441aa557397345090713222a735beb32bc9f1b6cd7971536de9ca427db8650f053917040
7
- data.tar.gz: 1ba36cba82aafbb2bb003e016f0817884b1129a7d0a8b2be7385e438999e6e7728224f7e146d4de611e171fc851ae64ebea3aa7bfa65f55868cb0c5477d8ecff
6
+ metadata.gz: 3e24a71c6ace693525fc4866aaa21ee7c75f7251d5d6e0820da3b6abc0bd6fd5921b20c2edbb7fc656b75991e1fc5607357dc02870072900e7b6ef972c840280
7
+ data.tar.gz: 5b75200355c62c549c2d61820e74e1cc71e4ebce68a1e390af60dbe76b6e1b7a69e71d73c8121db42ea05fc296db4ecc1f5776c71ad988685f13f71fc00fec66
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.2.1 (2021-12-15)
2
+
3
+ - Added support for Active Record 7
4
+
1
5
  ## 0.2.0 (2021-04-21)
2
6
 
3
7
  - Added support for pgvector
data/README.md CHANGED
@@ -23,7 +23,7 @@ rails generate neighbor:cube
23
23
  rails db:migrate
24
24
  ```
25
25
 
26
- For vector, install [pgvector](https://github.com/ankane/pgvector#installation) and run:
26
+ For vector, [install pgvector](https://github.com/ankane/pgvector#installation) and run:
27
27
 
28
28
  ```sh
29
29
  rails generate neighbor:vector
@@ -39,7 +39,7 @@ class AddNeighborVectorToItems < ActiveRecord::Migration[6.1]
39
39
  def change
40
40
  add_column :items, :neighbor_vector, :cube
41
41
  # or
42
- add_column :items, :neighbor_vector, :vector, limit: 3
42
+ add_column :items, :neighbor_vector, :vector, limit: 3 # dimensions
43
43
  end
44
44
  end
45
45
  ```
@@ -88,7 +88,7 @@ class Item < ApplicationRecord
88
88
  end
89
89
  ```
90
90
 
91
- For inner product with cube, see [this example](examples/disco_user_recs.rb).
91
+ For inner product with cube, see [this example](examples/disco_user_recs_cube.rb).
92
92
 
93
93
  Records returned from `nearest_neighbors` will have a `neighbor_distance` attribute
94
94
 
@@ -116,12 +116,12 @@ For vector, add an approximate index to speed up queries. Create a migration wit
116
116
  ```ruby
117
117
  class AddIndexToItemsNeighborVector < ActiveRecord::Migration[6.1]
118
118
  def change
119
- add_index :items, :neighbor_vector, using: :ivfflat
119
+ add_index :items, :neighbor_vector, using: :ivfflat, opclass: :vector_l2_ops
120
120
  end
121
121
  end
122
122
  ```
123
123
 
124
- Add `opclass: :vector_cosine_ops` for cosine distance and `opclass: :vector_ip_ops` for inner product.
124
+ Use `:vector_cosine_ops` for cosine distance and `:vector_ip_ops` for inner product.
125
125
 
126
126
  Set the number of probes
127
127
 
@@ -159,9 +159,11 @@ recommender.fit(data)
159
159
  Use item factors for the neighbor vector
160
160
 
161
161
  ```ruby
162
+ movies = []
162
163
  recommender.item_ids.each do |item_id|
163
- Movie.create!(name: item_id, neighbor_vector: recommender.item_factors(item_id))
164
+ movies << {name: item_id, neighbor_vector: recommender.item_factors(item_id)}
164
165
  end
166
+ Movie.insert_all!(movies) # use create! for Active Record < 6
165
167
  ```
166
168
 
167
169
  And get similar movies
@@ -171,7 +173,7 @@ movie = Movie.find_by(name: "Star Wars (1977)")
171
173
  movie.nearest_neighbors(distance: "cosine").first(5).map(&:name)
172
174
  ```
173
175
 
174
- [Complete code](examples/disco_item_recs.rb)
176
+ See the complete code for [cube](examples/disco_item_recs_cube.rb) and [vector](examples/disco_item_recs_vector.rb)
175
177
 
176
178
  ## Upgrading
177
179
 
@@ -204,5 +206,11 @@ To get started with development:
204
206
  git clone https://github.com/ankane/neighbor.git
205
207
  cd neighbor
206
208
  bundle install
209
+ createdb neighbor_test
210
+
211
+ # cube
207
212
  bundle exec rake test
213
+
214
+ # vector
215
+ EXT=vector bundle exec rake test
208
216
  ```
@@ -1,3 +1,3 @@
1
1
  module Neighbor
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/neighbor.rb CHANGED
@@ -44,5 +44,9 @@ ActiveSupport.on_load(:active_record) do
44
44
  end
45
45
 
46
46
  # prevent unknown OID warning
47
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(Neighbor::RegisterTypes)
47
+ if ActiveRecord::VERSION::MAJOR >= 7
48
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.singleton_class.prepend(Neighbor::RegisterTypes)
49
+ else
50
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(Neighbor::RegisterTypes)
51
+ end
48
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neighbor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.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: 2021-04-22 00:00:00.000000000 Z
11
+ date: 2021-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
- rubygems_version: 3.2.3
63
+ rubygems_version: 3.2.32
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: Nearest neighbor search for Rails and Postgres