neighbor 0.5.1 → 0.5.2

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: ee3864aa1511aa273c2d619e408bff8bcb491adc6dd111c5c88f7b79ef0baafc
4
- data.tar.gz: 7d79f79814a0041e77d18edf83cb87b5fba5f59d1a25a71370d8b28c6a5cd289
3
+ metadata.gz: fb8418a71159a849442d146643f732c28d10a5237d94a5b5b7d7466a224a40b5
4
+ data.tar.gz: 8a7ededb3071fdef4a77bbbdf4596d74ed323327d4d29ea15538e344d25af2f7
5
5
  SHA512:
6
- metadata.gz: c8d63b19a366d670212d6d5296f3b0f0de45e007635b7026bc9474bbd9248c9fc9a7ba4ee8b7c1b796ecdd7eef93460fe4e4e746eb49a8c19d471f4827530ecf
7
- data.tar.gz: c371a55e3f1579b6a62fcc5cc55c5ac54cb318faa12278c736089b97de1990ecf56a17863bcc7043b4a2cde9be50cb02b8b7dcecaf5032d371e1675a062723f2
6
+ metadata.gz: 05b3b8ccd07570f531aef0132a80563aef046b88508e732b2f16fe02f6c0303bd6f6fdb00804a646845086ba7fd133358503a7c7b69b098c02f548434c859575
7
+ data.tar.gz: 9bcb61d4e1453e30daeab1fff0364c023278405d170b435cdfb262aac0aa0d91622e19471fbf3f3076e4c944d09318dc81cf334fdac7767fa6f72d95c8560907
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.5.2 (2025-01-05)
2
+
3
+ - Improved support for Postgres arrays
4
+
1
5
  ## 0.5.1 (2024-12-03)
2
6
 
3
7
  - Added experimental support for MariaDB 11.7
data/README.md CHANGED
@@ -306,12 +306,14 @@ class AddEmbeddingToItems < ActiveRecord::Migration[8.0]
306
306
  def change
307
307
  # Rails 8+
308
308
  create_virtual_table :items, :vec0, [
309
+ "id integer PRIMARY KEY AUTOINCREMENT NOT NULL",
309
310
  "embedding float[3] distance_metric=L2"
310
311
  ]
311
312
 
312
313
  # Rails < 8
313
314
  execute <<~SQL
314
315
  CREATE VIRTUAL TABLE items USING vec0(
316
+ id integer PRIMARY KEY AUTOINCREMENT NOT NULL,
315
317
  embedding float[3] distance_metric=L2
316
318
  )
317
319
  SQL
@@ -329,16 +331,6 @@ ActiveRecord::SchemaDumper.ignore_tables += [
329
331
  ]
330
332
  ```
331
333
 
332
- Create a model with `rowid` as the primary key
333
-
334
- ```ruby
335
- class Item < ApplicationRecord
336
- self.primary_key = "rowid"
337
-
338
- has_neighbors :embedding, dimensions: 3
339
- end
340
- ```
341
-
342
334
  Get the `k` nearest neighbors
343
335
 
344
336
  ```ruby
@@ -348,7 +340,7 @@ Item.where("embedding MATCH ?", [1, 2, 3].to_s).where(k: 5).order(:distance)
348
340
  Filter by primary key
349
341
 
350
342
  ```ruby
351
- Item.where(rowid: [2, 3]).where("embedding MATCH ?", [1, 2, 3].to_s).where(k: 5).order(:distance)
343
+ Item.where(id: [2, 3]).where("embedding MATCH ?", [1, 2, 3].to_s).where(k: 5).order(:distance)
352
344
  ```
353
345
 
354
346
  ### Int8 Vectors
@@ -19,6 +19,9 @@ module Neighbor
19
19
 
20
20
  # prevent unknown OID warning
21
21
  ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.singleton_class.prepend(RegisterTypes)
22
+
23
+ # support vector[]/halfvec[]
24
+ ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array.prepend(ArrayMethods)
22
25
  end
23
26
 
24
27
  module RegisterTypes
@@ -39,5 +42,17 @@ module Neighbor
39
42
  end
40
43
  end
41
44
  end
45
+
46
+ ArrayWrapper = Struct.new(:to_a)
47
+
48
+ module ArrayMethods
49
+ def type_cast_array(value, method, ...)
50
+ if (subtype.is_a?(Neighbor::Type::Vector) || subtype.is_a?(Neighbor::Type::Halfvec)) && method != :deserialize && value.is_a?(::Array) && value.all? { |v| v.is_a?(::Numeric) }
51
+ super(ArrayWrapper.new(value), method, ...)
52
+ else
53
+ super
54
+ end
55
+ end
56
+ end
42
57
  end
43
58
  end
@@ -1,3 +1,3 @@
1
1
  module Neighbor
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neighbor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-03 00:00:00.000000000 Z
10
+ date: 2025-01-05 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -24,7 +23,6 @@ dependencies:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: '7'
27
- description:
28
26
  email: andrew@ankane.org
29
27
  executables: []
30
28
  extensions: []
@@ -62,7 +60,6 @@ homepage: https://github.com/ankane/neighbor
62
60
  licenses:
63
61
  - MIT
64
62
  metadata: {}
65
- post_install_message:
66
63
  rdoc_options: []
67
64
  require_paths:
68
65
  - lib
@@ -77,8 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
74
  - !ruby/object:Gem::Version
78
75
  version: '0'
79
76
  requirements: []
80
- rubygems_version: 3.5.22
81
- signing_key:
77
+ rubygems_version: 3.6.2
82
78
  specification_version: 4
83
79
  summary: Nearest neighbor search for Rails
84
80
  test_files: []