rrf 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -6
- data/lib/rrf/version.rb +1 -1
- data/lib/rrf.rb +1 -1
- metadata +45 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d23d3c84e7e2137eec0c67f900d1f6467ed2d0d69d2b33ab4b941a41dae41bd
|
4
|
+
data.tar.gz: 055da373ae7eb8a1e2f5c4cb00c0d37015911a97964d17187fc8a5a434d370c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec77c2eb56856d7289a6fa4d78f62fa2cfa91ba2f0993d69dbe3e88b293f097f42e88322c9c89841636ae494dc94656ace123dfba4220da8b71ae84bf8813775
|
7
|
+
data.tar.gz: 8e76be5b62fb140410f974338528ab2e5b81ce0a81064a7d7e310abe1e06ced2c1acd6d53360fc5a768374d56a7b4e40936dd899074f8ba66aeee5f41868c930
|
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("
|
56
|
+
es_result = Chunk.search("alpaca", load: false, limit: 50)
|
57
57
|
|
58
58
|
# Perform ActiveRecord nearest neighbor search
|
59
|
-
query_embedding =
|
60
|
-
ar_result = Chunk.
|
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
|
80
|
+
After checking out the repo, run
|
81
81
|
|
82
|
-
|
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
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] }
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rrf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Petersen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
12
|
-
dependencies:
|
11
|
+
date: 2024-08-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: elasticsearch
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
13
55
|
description: This gem provides an implementation of Reciprocal Rank Fusion (RRF) to
|
14
56
|
merge results from different search engines. Initially supporting Active Record
|
15
57
|
and Elasticsearch.
|