• Stars
    star
    1,351
  • Rank 33,450 (Top 0.7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 12 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ‘๐Ÿ‘Ž A recommendation engine using Likes and Dislikes for your Ruby app

Recommendable

Recommendable is a gem that allows you to quickly add a recommendation engine for Likes and Dislikes to your Ruby application using my version of Jaccardian similarity and memory-based collaborative filtering.

Requirements

  • Ruby >= 1.9.3
  • ActiveRecord, Sequel, DataMapper, Mongoid, or MongoMapper (your models must have an id field)
  • Sidekiq, Resque, or DelayedJob (optional but highly recommended)

Bundling one of the queueing systems above is highly recommended to avoid having to manually refresh users' recommendations. If you bundle Sidekiq, you should also include 'sidekiq-middleware' in your Gemfile to ensure that a user will not get enqueued more than once at a time. If bundling Resque, you should include 'resque-loner' for this. As far as I know, there is no current way to avoid duplicate jobs in DelayedJob. Queueing for Torquebox is also supported.

Installation

Add the following to your application's Gemfile:

gem 'recommendable'

Please note that you currently must need to place Recommendable below your ORM and queueing system in the Gemfile. If you are using Sidekiq and ActiveRecord, please place gem recommendable below both gem 'rails' and gem 'sidekiq'.

After bundling, you should configure Recommendable. Do this somewhere after you've required it, but before it's actually used. For example, Rails users would create an initializer (config/initializers/recommendable.rb):

require 'redis'

Recommendable.configure do |config|
  # Recommendable's connection to Redis.
  #
  # Default: localhost:6379/0
  config.redis = Redis.new(:host => 'localhost', :port => 6379, :db => 0)

  # A prefix for all keys Recommendable uses.
  #
  # Default: recommendable
  config.redis_namespace = :recommendable

  # Whether or not to automatically enqueue users to have their recommendations
  # refreshed after they like/dislike an item.
  #
  # Default: true
  config.auto_enqueue = true

  # The number of nearest neighbors (k-NN) to check when updating
  # recommendations for a user. Set to `nil` if you want to check all
  # neighbors as opposed to a subset of the nearest ones. Set this to a lower
  # number to improve Redis memory usage.
  #
  # Default: nil
  config.nearest_neighbors = nil

  # Like kNN, but also uses some number of most dissimilar users when
  # updating recommendations for a user. Because, hey, disagreements are
  # just as important as agreements, right? If `nearest_neighbors` is set to
  # `nil`, this configuration is ignored. Set this to a lower number
  # to improve Redis memory usage.
  #
  # Default: nil
  config.furthest_neighbors = nil

  # The number of recommendations to store per user. Set this to a lower
  # number to improve Redis memory usage.
  #
  # Default: 100
  config.recommendations_to_store = 100
end

The values listed above are the defaults. I recommend playing around with the nearest_neighbors setting. A higher value will provide more accurate recommendations at the cost of more time spent generating them.

If your application uses multiple ORMs, you must configure Recommendable to use the correct one. For example:

Recommendable.configure do |config|
  config.orm = :active_record
end

Important: in case of active_record with id of type uuid, use :active_record_uuid.

Usage

In your model that will be receiving recommendations:

class User
  recommends :movies, :books, :minerals, :other_things

  # ...
end

To ensure that users' recommendations are processed after they rate items, make sure your bundled queue system is running:

# sidekiq
$ [bundle exec] sidekiq -q recommendable
# resque
$ QUEUE=recommendable [bundle exec] rake environment resque:work
# delayed_job
$ [bundle exec] rake jobs:work

That's it! Please note, however, that currently only one model may receive recommendations.

For more details on how to use Recommendable in your application, check out the detailed guide or see the documentation.

Installing Redis

Recommendable requires Redis to deliver recommendations. The collaborative filtering logic is based almost entirely on set math, and Redis is blazing fast for this.

NOTE: Your Redis database MUST be persistent. All ratings are stored permanently in Redis. If you're worried about Redis losing data, keep backups.

Mac OS X

For Mac OS X users, homebrew is by far the easiest way to install Redis. Make sure to read the caveats after installation!

$ brew install redis

Linux

For Linux users, there is a package on apt-get.

$ sudo apt-get install redis-server
$ redis-server

Redis will now be running on localhost:6379. After a second, you can hit ctrl-\ to detach and keep Redis running in the background.

Why not stars?

I'll let Randall Munroe of XKCD take this one for me:

I got lost and wandered into the world's creepiest cemetery, where the headstones just had names and star ratings. Freaked me out. When I got home I tried to leave the cemetery a bad review on Yelp, but as my hand hovered over the 'one star' button I felt this distant chill ...

Links

Build Status Coverage Climate Dependencies gittip

More Repositories

1

api-pagination

๐Ÿ“„ Link header pagination for Rails and Grape APIs.
Ruby
689
star
2

spec-me-maybe

โ“ Introduces the `maybe` syntax to RSpec.
Ruby
167
star
3

inflections

๐Ÿ‡ช๐Ÿ‡ธ Sane and multilingual singularization/pluralization rules for ActiveSupport and Rails.
Ruby
88
star
4

goodbre.ws

๐Ÿป An example implementation of Recommendable. Unfortunately now defunct.
Ruby
59
star
5

Sunscreen

๐ŸŒ… A macOS app that sets your wallpaper based on sunrise and sunset.
Swift
58
star
6

rack-console

๐Ÿ’ป `rails console` for your Rack applications
Ruby
27
star
7

geocodio

A ruby client for the http://geocod.io/ API. Geocode with ease.
Ruby
20
star
8

dotfiles

๐ŸŸ #!/usr/bin/env fish
Shell
19
star
9

api-benchmarks

Benchmarks for various Ruby API frameworks.
Ruby
18
star
10

quiet_safari

๐Ÿ™Š If you donโ€™t care about /apple-touch-icon.png being a 404
Ruby
17
star
11

new_relic-discourse

A New Relic plugin for Discourse forums.
Ruby
17
star
12

pry-suite

A metagem to install Pry with many useful plugins.
Ruby
15
star
13

language-fish-shell

๐ŸŸ Atom snippets and syntax highlighting for Fish, the friendly interactive shell.
12
star
14

emoji

10
star
15

sparkles

โœจ Recognize teammates in slack by awarding them sparkles!
Ruby
6
star
16

vim-ariake-dark

The Ariake Dark theme for Vim
Vim Script
5
star
17

snap

A bootstrapped IRC bot using Cinch. I write plugins so you don't have to.
Ruby
5
star
18

squint-test

Do squint tests on your code in Atom!
CoffeeScript
5
star
19

davidcelis.github.io

๐Ÿ“ฐ My old homepage and blog, written with Jekyll
HTML
5
star
20

no-tco.safariextension

A Safari extension to replace t.co links with their original URL.
JavaScript
4
star
21

nook_stop_api

๐Ÿƒ Welcome to Nook Stop, a multimedia terminal from Nook Inc. This toy app is an example of how to build a GraphQL API in Ruby, powered by data from Animal Crossing: New Horizons.
HTML
4
star
22

davidcel.is

๐Ÿ“ My personal website and blog
Ruby
3
star
23

runmygi.st

Run arbitrary gists using Docker!
Ruby
3
star
24

gifs

๐ŸŽž A collection of gifs curated by and for David Celis
HTML
3
star
25

rspec-stackprof

Easily integrate stackprof with RSpec on Ruby 2.1.
Ruby
2
star
26

brewhouse

A Ruby wrapper for the BreweryDB API
Ruby
2
star
27

homebrew-spark

Ruby
1
star
28

gocean

A Go library to communicate with Digital Ocean's APIv2
1
star
29

dcelis_ebooks

๐Ÿฆ The home of my Twitter eBooks bot.
Ruby
1
star
30

my-tfe

My personal TFE setup
HCL
1
star
31

empty

This repository is empty, but it still has a commit
1
star
32

wing_clip

Sync your Foursquare check-in historyโ€”past, present, and futureโ€”to Google Calendar.
Ruby
1
star
33

SpriteSheet

A small helper class to convert .gifs to sprites.
Ruby
1
star
34

language-thrift

Atom syntax highlighting and snippets for Thrift files.
CoffeeScript
1
star
35

advent-of-code-2020

๐ŸŽ„ My solutions to 2020's Advent of Code, in Ruby
Ruby
1
star
36

puddle

WIP: A MUD server written in Node.js
JavaScript
1
star