The Ruby SDK provides a convenient wrapper for PredictionIO Event Server API and Engine 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 2+ required!
The module is published to RubyGems and can be installed directly by:
gem install predictionio
Or using Bundler with:
gem 'predictionio', '0.12.1'
Please refer to Event Server documentation for event format and how the data can be collected from your app.
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']))
client.create_event(
'$set',
'user',
user_id
)
client.create_event(
'$set',
'item',
item_id,
{ 'properties' => { 'categories' => ['Category 1', 'Category 2'] } }
)
NOTE: channels are supported in PIO version >= 0.9.2 only. Channel must be created first.
client.create_event(
'$set',
'item',
item_id,
{ 'properties' => { 'categories' => ['Category 1', 'Category 2'], 'channel' => 'test-channel'} }
)
client.create_event(
'rate',
'user',
user_id, {
'targetEntityType' => 'item',
'targetEntityId' => item_id,
'properties' => { 'rating' => 10 }
}
)
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.
# Define environmental variables.
ENV['PIO_ENGINE_URL'] = 'http://localhost:8000'
# Create PredictionIO engine client.
client = PredictionIO::EngineClient.new(ENV['PIO_ENGINE_URL'])
# Get 5 recommendations for items similar to 10, 20, 30.
response = client.send_query(items: [10, 20, 30], num: 5)
Please use the Apache mailing lists. Subscription instructions are here.
Use the Apache JIRA, and file any
issues under the Ruby SDK
component.
Please follow these instructions.