PLASMA (Personalization Language for Segment of 1 Marketing Automation)


Recommendation schemes in Blueshift are built with a run-time language interpreter and execution engine called PLASMA which allows a developer to combine real time context of a user with pre-computed product rankings. Recommendation schemes are built as series of special purpose instructions that are executed in sequence. Such sets of instructions are run to recommend to each user products from the catalog that are tailored to their most recent behavior, CRM attributes or inferred affinities. The following diagram illustrates how the runtime engine sits between backend systems and Recommendation Studio and powers our unique Segment of One marketing automation platform.

Plasma Engine Diagram

Plasma Engine Diagram

As the diagram above illustrates the backend systems follow a lambda architecture where incoming events, user and product attribute updates are sent in parallel to two systems, one for updating user profiles, product records and event details in real time and one for running machine learning models and long time range aggregates on a hourly or daily basis. Plasma engine then allows combining real time context with the batch compute aggregates using a domain specific language in which a developer can code up a set of instructions to design and deploy 1:1 recommendations at scale.

Each set of instructions are run inside an interpreter engine that is bootstrapped with a user context i.e. each invocation starts by fetching the user profile to whom the recommendations are being computed for. Each set of instructions is then executed sequentially. The language is designed to allow specific operations for fetching data from backend store and joining it with relevant user and product attributes. Bulk of the operations work with product arrays to mix and match what’s applicable to the user context. It is not designed to be a general purpose programming language and as such should not be compared to one. The syntax follows the common object oriented programming guidelines in how variables are initialized, functions are called and return values stored.


1. Getting started

Access to Plasma engine is enabled as a premium feature that allows developers and marketers to code up recommendation schemes using IDE built into the dashboard. Please contact your support team if you require access.


2. Code Samples

Easiest way to experience power of PLASMA language is to walk through sample use cases. Below we describe few use cases and describe various functions and operators used and look at sample output.


Use case 1 : Recommendations for Abandoned View

A common use case for recommendations is when a user visits your site or app and have not finished a goal you expect them to. For example on an e-commerce site a user might have viewed a product but did not go on to finish purchasing that product and we like to recommend to that user best sellers from the category of that product as an alternative. See sample code and IDE screenshot below and we will walk through each instruction and see what's going on.

recent_viewed = fetch(data_store: 'user_events', key: 'view', days_to_look_back: 7, num_products_to_show: 1);
recent_purchased = fetch(data_store: 'user_events', key: 'purchase', days_to_look_back: 7);
abandoned_products = subtract(recent_viewed, recent_purchased);
block1 = recommend(products: abandoned_products, count: 1, target: 'block1', template_name: 'Most recent abandoned view');

related_products = array(type: 'product');
if length_greater_than(key: abandoned_products, length: 0 ) then
  abandoned_product_0 = select(abandoned_products, index: 0);
  abandoned_product_0_cat = get_attribute(abandoned_product_0, attribute_key:'category', attribute_index: -1);
  if is_not_empty(abandoned_product_0_cat) then
    category_top_sellers = fetch(data_store: 'product_attribute_scores', key: 'category.top_selling.products', category: abandoned_product_0_cat);
    related_products = filter_products(category_top_sellers, ignore_purchased: true, ignore_availability: true);
block2 = recommend(products: related_products, count: 4, target: 'block2', template_name: 'Category upsell based on most recent abandoned view');

If you have access to Plasma IDE go ahead and copy the code from above and paste it into your IDE like below

Let's now look at each instruction and see what's going on.

  1. First line is a simple instruction to fetch from the user_events data store last viewed product by the user in the last 7 days. It returns an array with 1 product.
  2. Second line we fetch all purchases in the last 7 days
  3. Third line we subtract the two arrays to get a new array of abandoned products.
  4. Fourth line we use recommend call to build block1 with abandoned product which we can use in messaging to the user reminding them of their most recent view.
  5. From line 6 to 14 we build a block of recommendations based on the best selling products from the category of the abandoned product.
  6. In line 6 we initialize an empty array of products as a place holder for recommendations
  7. In line 7 we check if the abandoned products array is empty since the last viewed item could have been already purchased.
  8. In line 8 we fetch the first product from the array
  9. In line 9 we use get_attribute function to look up category attribute of the product
  10. Through line 10 to 13 we check if the category variable is empty or not and if not empty use that
  11. In line 11 we fetch from the product_attribute_scores data store best selling products for this category
  12. In line 12 we filter the category best sellers to make sure they are still available and remove any previously purchased items by this user and store the output in the related products variable.
  13. In line 13 we close the conditional
  14. In line 14 we close the conditional
  15. In line 15 we use recommend function again to build block2 with the related products and use variable template_name to give it a readable description.

You can see the output of the instructions visually and as raw data in the IDE screenshots below. Congratulations you have built your first recommendation scheme. You can use what you have built in your email or push templates like all other schemes. See Dynamic Content for more details.

Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.