Skip to content

Commit

Permalink
Merge pull request #3 from assaydepot/readme
Browse files Browse the repository at this point in the history
Readme
  • Loading branch information
cpetersen authored Jul 18, 2024
2 parents 58abc0b + 93c7bc9 commit 492a9a2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ end

### Performing Searches and Fusing Results

You can perform searches using ActiveRecord and Searchkick, and then fuse the results using the fuse method:
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)):

```ruby
# Configure the constant value if needed
Expand All @@ -53,11 +53,11 @@ RRF.configure do |config|
end

# Perform Searchkick search
es_result = Chunk.search("hi", load: false, limit: 50)
es_result = Chunk.search("alpaca", load: false, limit: 50)

# Perform ActiveRecord nearest neighbor search
query_embedding = [0.1, 0.2, 0.3, ...] # Example embedding
ar_result = Chunk.where("body ilike ?", "%hi%").limit(50)
query_embedding = Candle::Model.new.embedding("alpaca") # You'd want to cache the model in memory
ar_result = Chunk.all.nearest_neighbors(:embedding768, query_embedding, distance: :cosine).limit(50)

# Fuse the results and limit to 10
result = Chunk.fuse(ar_result, es_result, limit: 10)
Expand Down

0 comments on commit 492a9a2

Please sign in to comment.