Graph Kit for Ruby: Let’s Build a Recommendation Engine for a Spree Store

  

part-1 (1)

Hi there! My name is Daniel and I’m a consulting Ruby developer here in Memphis, Tennessee. The past year or two I’ve mostly focused on building online stores. At Graph Story’s invitation I recently set out to build a Ruby project demonstrating a simple yet valuable integration with a graph database.

The little I knew about graphs before this project was all theoretical so I decided to start by learning more about Neo4j, the open source graph database technology behind Graph Story’s service offerings.

Poking around online to find graph database resources I wound up at Neo4j’s homepage and found that some of its founders published a book with O’Reilly. They were giving away copies in exchange for email addresses. Sold! The book mentioned several good use cases for graph databases, but recommendation engines jumped off the page for me.

You’ve undoubtedly seen automated recommendation tools in action around the web. The first one that came to mind for me is the one at the bottom of every product page on Amazon saying “Customers Who Bought This Item Also Bought…”. Turns out we can make our own fairly easily with a graph database!

other-recommendation-suggestions

What will our graph kit starter project do?

We’re going to have an online store. It’s going to sell pet products in various colors and product families. You might see a pink leash, a yellow collar, or a red pillow. We’ll whip up some artificial customers with interesting buying patterns and have them purchase a few hundred things from our online pet supply store.

When that’s done, we’ll be able to dig in to the graph our purchase activities have generated and uncover some useful data about customer purchasing preferences. Armed with this new data, we’ll set up an Amazon-style “customers who bought pink pillows also bought pink leashes” pane on every product page of our store in hopes of increasing sales with relevant recommendations.

pink-shirt-graph

You can see in the image above how a pink shirt appealed to one customer who collects pink things but it also appealed to another customer who collects shirts. Digging these connections out of our graph will make it easier for us to present customers with targeted recommendations of things they might actually want to buy.

Where can I get the code?

All code for this project is shared on Graph Story’s GitHub account: The Graph Kit for Ruby is a mostly stock Spree store with some simple Neo4j integrations that will give you a head start on building your own high-value graph solutions. If you read the source code closely you can probably figure out where we’re going in posts 2 and 3 in this series ;)

How will we deploy it?

We’re going to use Engine Yard to run our app server and a PostgreSQL database to store the basic product catalog and order history. New products and new orders are also going to be streamed directly to a Neo4j database so that we can build our recommendations in real time. We’ll take a fairly naive approach to this streaming in the interests of keeping this series of posts easily digestible.

Up next: building the sample store and integrating it with Neo4j

Stay tuned for part 2 in this series: “Bootstrapping a Spree Store and Integrating With Neo4j” where I’ll walk through the steps required to create your own Spree store, load up those fake customers, products, and purchases.

Once that’s in place we’ll layer in our “customers also bought” widget on the Spree frontend. In part 3 we’ll walk through the process of deploying the working Spree app to an Engine Yard cloud server that integrates with a free trial graph database provided by Graph Story.

This guest post was originally published by our friends at Graph Story.

Daniel Pritchett

Comments

Subscribe to our Blog