Pipeless

Documentation

Sorted Content

Get a personalized sorting of a pre-defined set of content based on a user’s interests and what similar users have engaged with. This algorithm utilizes collaborative filtering based on selected engagement signals and categories/tags.

Examples include:

  • Your Search Results
  • Promoted Products for You
  • Featured Articles You Might Like

Code Example

Take a look at this example of using the Sorted Content endpoint, and read the detailed description below explaining each part of this code.

const data = JSON.stringify({
     "object": {
          "id": "Tim",
          "type": "user"
     },
     "content_object_type": "article",
     "content_ids": [
          "3255",
          "2225",
          "4565",
          "6354",
          "7346",
          "4634",
          "4778",
          "8547"
     ],
     "primary_positive_relationship_type": "liked",
     "secondary_positive_relationship_type": "viewed",
     "primary_negative_relationship_type": "disliked",
     "content_tagged_relationship_type": "taggedWith",
     "content_tag_object_type": "tag"
});

const xhr = new XMLHttpRequest();

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.pipeless.io/v1/apps/123/algos/recommendations/sorted-content");
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("content-type", "application/json");

xhr.send(data);
import requests

url = "https://api.pipeless.io/v1/apps/123/algos/recommendations/sorted-content"

payload = {
     "object": {
          "id": "Tim",
          "type": "user"
     },
     "content_object_type": "article",
     "content_ids": [
          "3255",
          "2225",
          "4565",
          "6354",
          "7346",
          "4634",
          "4778",
          "8547"
     ],
     "primary_positive_relationship_type": "liked",
     "secondary_positive_relationship_type": "viewed",
     "primary_negative_relationship_type": "disliked",
     "content_tagged_relationship_type": "taggedWith",
     "content_tag_object_type": "tag"
}
headers = {
    "accept": "application/json",
    "content-type": "application/json"
}

response = requests.request("GET", url, json=payload, headers=headers)

print(response.text)
require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://api.pipeless.io/v1/apps/123/algos/recommendations/sorted-content")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Get.new(url)
request["accept"] = 'application/json'
request["content-type"] = 'application/json'
request.body = "{\"object\":{\"id\":\"Tim\",\"type\":\"user\"},\"content_object_type\":\"article\",\"content_ids\":[\"3255\",\"2225\",\"4565\",\"6354\",\"7346\",\"4634\",\"4778\",\"8547\"],\"primary_positive_relationship_type\":\"liked\",\"secondary_positive_relationship_type\":\"viewed\",\"primary_negative_relationship_type\":\"disliked\",\"content_tagged_relationship_type\":\"taggedWith\",\"content_tag_object_type\":\"tag\"}"

response = http.request(request)
puts response.read_body
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.pipeless.io/v1/apps/123/algos/recommendations/sorted-content",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_POSTFIELDS => "{\"object\":{\"id\":\"Tim\",\"type\":\"user\"},\"content_object_type\":\"article\",\"content_ids\":[\"3255\",\"2225\",\"4565\",\"6354\",\"7346\",\"4634\",\"4778\",\"8547\"],\"primary_positive_relationship_type\":\"liked\",\"secondary_positive_relationship_type\":\"viewed\",\"primary_negative_relationship_type\":\"disliked\",\"content_tagged_relationship_type\":\"taggedWith\",\"content_tag_object_type\":\"tag\"}",
  CURLOPT_HTTPHEADER => [
    "accept: application/json",
    "content-type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"object\":{\"id\":\"Tim\",\"type\":\"user\"},\"content_object_type\":\"article\",\"content_ids\":[\"3255\",\"2225\",\"4565\",\"6354\",\"7346\",\"4634\",\"4778\",\"8547\"],\"primary_positive_relationship_type\":\"liked\",\"secondary_positive_relationship_type\":\"viewed\",\"primary_negative_relationship_type\":\"disliked\",\"content_tagged_relationship_type\":\"taggedWith\",\"content_tag_object_type\":\"tag\"}");
Request request = new Request.Builder()
  .url("https://api.pipeless.io/v1/apps/123/algos/recommendations/content")
  .get()
  .addHeader("accept", "application/json")
  .addHeader("content-type", "application/json")
  .build();

Response response = client.newCall(request).execute();
curl --request GET \
  --url https://api.pipeless.io/v1/apps/123/algos/recommendations/sorted-content \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '
  {
     "object": {
          "id": "Tim",
          "type": "user"
     },
     "content_object_type": "article",
     "content_ids": [
          "3255",
          "2225",
          "4565",
          "6354",
          "7346",
          "4634",
          "4778",
          "8547"
     ],
     "primary_positive_relationship_type": "liked",
     "secondary_positive_relationship_type": "viewed",
     "primary_negative_relationship_type": "disliked",
     "content_tagged_relationship_type": "taggedWith",
     "content_tag_object_type": "tag"
}
'

Here we're running this algo on App ID "123" where an object user "Tim" is the target who will being receiving personalized re-sorted content. The type of content that will be sorted is set to "article." The primary positive relationship is set to "liked" which means the algorithm is going to use "liked" relationships between users and articles to calculate recommendations. The secondary positive relationship of "viewed" adds a smaller weighting to factor in users who have viewed articles rather than only those who have liked articles. The content tagged relationship type is set to "taggedWith" and content tag object type to "tag" which will be used in weighing recommendations not just on collaborative filtering of articles ("users who liked and viewed articles like you also liked and viewed these other articles") but also on the tags that articles share.

To summarize, this example is: "get a recommended sort for this set of articles for Tim - articles that other users have liked and viewed who are users who had similar tastes as Tim based on Tim's previously liked and viewed articles - while also keeping articles more topically relevant to Tim's liked and viewed articles by factoring in tags on those articles"

Tutorial Example

You can see this API endpoint in action using our tutorial restaurant dataset here:
Sorted Content Tutorial Example

API Reference Documentation

You can read the reference docs for this endpoint here:
Get Sorted Content (for user)

Updated 3 months ago


What's Next

Related Accounts

Sorted Content


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.