Skip to main content

Complementary items

A complementary items query recommends items that go well with a set of items, typically items in a shopping cart or a viewing session. Use this for "customers also bought" or "goes well with" recommendations.

The key difference from similar items is that complementary items find items that complete or enhance the set rather than items that are similar.

Complementary items

Prerequisites

  1. An engine with item data configured
  2. A set of item IDs to find complementary items for (e.g., cart items)

Query example

Retrieve popular items to find complementary items for a cart:

{
"query": {
"type": "rank",
"from": "item",
"retrieve": [
{
"type": "column_order",
"columns": [{ "name": "popularity_score", "ascending": false }],
"limit": 100
}
],
"limit": 10
}
}

With similarity-based retrieval

For more relevant complementary items, use similarity search based on the cart items:

{
"query": {
"type": "rank",
"from": "item",
"retrieve": [
{
"type": "similarity",
"embedding_ref": "collaborative_embedding",
"query_encoder": {
"type": "precomputed_item",
"input_item_id": "$parameters.cart_item_id"
},
"limit": 50
}
],
"limit": 10
},
"parameters": {
"cart_item_id": "item123"
}
}