rrf 0.1.0 → 0.1.2

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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -6
  3. data/lib/rrf/version.rb +1 -1
  4. data/lib/rrf.rb +1 -1
  5. data/rrf.gemspec +43 -0
  6. metadata +47 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e291263a6f09f559b804dbcab1332b9b110d0a5ecb6c707d2156ad4583d9873
4
- data.tar.gz: 28524ae014e0c0ca2fa8a20f553008b3cf8b6c5e7df6101abeef514e325ab8f3
3
+ metadata.gz: 8fe716ce7d3ededc96a7f4c2889fedfb47f35dad8421b06fc2612a4c6f15a95b
4
+ data.tar.gz: c606c5d7cbb1adba77a2c00a4064edce6e5165074fc7386710ac21f9dc8ec338
5
5
  SHA512:
6
- metadata.gz: 3ba1b4d3d5c593c864ab81824b1236d99e3d2f9ad805c92f15b895504dbad84142de698363664f7ce83a2457ea04c1fc4655ddb7d8dda535b5564f089c9981a9
7
- data.tar.gz: d7bf0020c66eb425853e4135cb2c452000c388f190fdf094e41d556b6f4ead73e316d4c5f43893568d3a11b6a1cef47577dec921ba13e78d87b0718a9dcc8e60
6
+ metadata.gz: 61d01173570a12d1e13242d62f2d265cda4281e50fb0451ebfe7b8b5885cd832b8c1803bbed2053f160c7f0d39c4a870a169369afedd2e00ecf57e0af58f31e9
7
+ data.tar.gz: 8e53593ac2b6eadfe3c9b39dea093c02ee605fcb319d753fb90790663dfc431078eb3ab6e6c2a4277d426e94595378e195ef7f35325809569d83d7aa336e3152
data/README.md CHANGED
@@ -44,7 +44,7 @@ end
44
44
 
45
45
  ### Performing Searches and Fusing Results
46
46
 
47
- You can perform searches using ActiveRecord and Searchkick, and then fuse the results using the fuse method:
47
+ You can perform searches using ActiveRecord and Searchkick, and then fuse the results using the fuse method (the following relies on the [neighbor gem](https://github.com/ankane/neighbor) and the [red-candle gem](https://github.com/assaydepot/red-candle)):
48
48
 
49
49
  ```ruby
50
50
  # Configure the constant value if needed
@@ -53,11 +53,11 @@ RRF.configure do |config|
53
53
  end
54
54
 
55
55
  # Perform Searchkick search
56
- es_result = Chunk.search("hi", load: false, limit: 50)
56
+ es_result = Chunk.search("alpaca", load: false, limit: 50)
57
57
 
58
58
  # Perform ActiveRecord nearest neighbor search
59
- query_embedding = [0.1, 0.2, 0.3, ...] # Example embedding
60
- ar_result = Chunk.where("body ilike ?", "%hi%").limit(50)
59
+ query_embedding = Candle::Model.new.embedding("alpaca") # You'd want to cache the model in memory
60
+ ar_result = Chunk.all.nearest_neighbors(:embedding768, query_embedding, distance: :cosine).limit(50)
61
61
 
62
62
  # Fuse the results and limit to 10
63
63
  result = Chunk.fuse(ar_result, es_result, limit: 10)
@@ -77,9 +77,40 @@ end
77
77
 
78
78
  ## Development
79
79
 
80
- After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
80
+ After checking out the repo, run
81
81
 
82
- To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
82
+ ```sh
83
+ bundle install
84
+ ```
85
+
86
+ Then, run
87
+
88
+ ```sh
89
+ rake spec
90
+ ```
91
+ to run the tests.
92
+
93
+ To install this gem onto your local machine, run
94
+
95
+ ```sh
96
+ bundle exec rake install
97
+ ```
98
+
99
+ To release a new version, update the version number in version.rb, and then run
100
+
101
+ ```sh
102
+ bundle exec rake release
103
+ ```
104
+
105
+ which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
106
+
107
+ To use this locally during development, I like to include it whatever project I'm working by adding the following to the `Gemfile` of the other project
108
+
109
+ ```ruby
110
+ gem "rrf", path: '/what/ever/path/you/choose/rrf'
111
+ ```
112
+
113
+ Then bundle and it will use your development copy.
83
114
 
84
115
  ## Contributing
85
116
 
data/lib/rrf/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RRF
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/rrf.rb CHANGED
@@ -48,7 +48,7 @@ module RRF
48
48
 
49
49
  # Sort by score and limit results
50
50
  top_record_ids = record_scores.sort_by { |_id, result| -result[:score] }.to_h.keys.first(limit)
51
-
51
+
52
52
  # Load actual records from ActiveRecord
53
53
  self.where(id: top_record_ids).index_by(&:id).values_at(*top_record_ids).each do |record|
54
54
  record.define_singleton_method(:_rrf_score) { record_scores[record.id][:score] }
data/rrf.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rrf/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rrf"
7
+ spec.version = RRF::VERSION
8
+ spec.authors = ["Chris Petersen"]
9
+ spec.email = ["chris@scientist.com"]
10
+
11
+ spec.summary = %q{A Ruby gem for Reciprocal Rank Fusion across different search engines}
12
+ spec.description = %q{This gem provides an implementation of Reciprocal Rank Fusion (RRF) to merge results from different search engines. Initially supporting Active Record and Elasticsearch.}
13
+ spec.homepage = "https://github.com/assaydepot/rrf"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+ # spec.metadata["changelog_uri"] = spec.homepage
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) ||
28
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
29
+ end
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ # Uncomment to register a new dependency of your gem
36
+ # spec.add_dependency "example-gem", "~> 1.0"
37
+ spec.add_development_dependency "rspec"
38
+ spec.add_development_dependency "elasticsearch"
39
+ spec.add_development_dependency "faraday"
40
+
41
+ # For more information and examples about making a new gem, check out our
42
+ # guide at: https://bundler.io/guides/creating_gem.html
43
+ end
metadata CHANGED
@@ -1,15 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rrf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Petersen
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-07-16 00:00:00.000000000 Z
12
- dependencies: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rspec
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: elasticsearch
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: faraday
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
13
54
  description: This gem provides an implementation of Reciprocal Rank Fusion (RRF) to
14
55
  merge results from different search engines. Initially supporting Active Record
15
56
  and Elasticsearch.
@@ -28,6 +69,7 @@ files:
28
69
  - lib/configuration.rb
29
70
  - lib/rrf.rb
30
71
  - lib/rrf/version.rb
72
+ - rrf.gemspec
31
73
  - sig/rrf.rbs
32
74
  homepage: https://github.com/assaydepot/rrf
33
75
  licenses:
@@ -35,7 +77,6 @@ licenses:
35
77
  metadata:
36
78
  homepage_uri: https://github.com/assaydepot/rrf
37
79
  source_code_uri: https://github.com/assaydepot/rrf
38
- post_install_message:
39
80
  rdoc_options: []
40
81
  require_paths:
41
82
  - lib
@@ -50,8 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
91
  - !ruby/object:Gem::Version
51
92
  version: '0'
52
93
  requirements: []
53
- rubygems_version: 3.5.3
54
- signing_key:
94
+ rubygems_version: 3.6.9
55
95
  specification_version: 4
56
96
  summary: A Ruby gem for Reciprocal Rank Fusion across different search engines
57
97
  test_files: []