Apache PredictionIO SDK Ruby Incubator

Clone this repo:
  1. 131f949 bump version numbers by EmergentOrder · 1 year, 7 months ago develop master v0.9.6
  2. 0cafb96 Merge pull request #12 from PredictionIO/master by EmergentOrder · 1 year, 7 months ago v0.9.5
  3. 9590984 Merge pull request #11 from PredictionIO/develop by EmergentOrder · 1 year, 7 months ago
  4. 32d5d67 Merge pull request #10 from EmergentOrder/develop by EmergentOrder · 1 year, 7 months ago
  5. 00d99ba add missing require to README by EmergentOrder · 1 year, 7 months ago

PredictionIO Ruby SDK

Build Status Code Climate Dependency Status Gem Version

The Ruby SDK provides a convenient wrapper for the PredictionIO API. It allows you to quickly record your users' behavior and retrieve personalized predictions for them.


Full Ruby SDK documentation can be found here.

Please see the PredictionIO App Integration Overview to understand how the SDK can be used to integrate PredictionIO Event Server and Engine with your application.


Ruby 1.9.3+ required!

The module is published to RubyGems and can be installed directly by:

gem install predictionio

Or using Bundler with:

gem 'predictionio', '0.9.6'

Sending Events to Event Server

Please refer to Event Server documentation for event format and how the data can be collected from your app.

Instantiate Event Client and connect to PredictionIO Event Server

require 'predictionio'

# Define environment variables.
ENV['PIO_THREADS'] = '50' # For async requests.
ENV['PIO_EVENT_SERVER_URL'] = 'http://localhost:7070'
ENV['PIO_ACCESS_KEY'] = 'YOUR_ACCESS_KEY' # Find your access key with: `$ pio app list`.

# Create PredictionIO event client.
client = PredictionIO::EventClient.new(ENV['PIO_ACCESS_KEY'], ENV['PIO_EVENT_SERVER_URL'], Integer(ENV['PIO_THREADS']))

Create a $set user event and send it to Event Server


Create a $set item event and send it to Event Server

  { 'properties' => { 'categories' => ['Category 1', 'Category 2'] } }

Create a user ‘rate’ item event and send it to Event Server

  user_id, {
    'targetEntityType' => 'item',
    'targetEntityId' => item_id,
    'properties' => { 'rating' => 10 }

Asynchronous request

To send an async request, simply use the acreate_event method instead of create_event. Be aware that the asynchronous method does not throw errors. It's best to use the synchronous method when first getting started.

Query PredictionIO Engine

Connect to the Engine:

# Define environmental variables.
ENV['PIO_ENGINE_URL'] = 'http://localhost:8000'

# Create PredictionIO engine client.
client = PredictionIO::EngineClient.new(ENV['PIO_ENGINE_URL'])

Send a prediction query to the engine and get the predicted result:

# Get 5 recommendations for items similar to 10, 20, 30.
response = client.send_query(items: [10, 20, 30], num: 5)


View Google Group

Issue Tracker

Use JIRA or GitHub Issues.


We follow the [git-flow] (http://nvie.com/posts/a-successful-git-branching-model/) model where all active development goes to the develop branch, and releases go to the master branch. Pull requests should be made against the develop branch and include relevant tests, if applicable. Please sign our Contributor Agreement before submitting a pull request.


Apache License 2.0.